I have control with custom drawings, let’s call it Surface.
I want to embed some winforms controls into that Surface. But also I want to draw some custom drawings (connectors), depending on controls location, size, etc.
I tried to give the responsibility to draw those connectors to child controls themselves, so any of my child control was just bigger in size and included all the necessary drawings. I used Parent.InvokePaint call to draw parent background when needed (and I also tried transparent background).
The drawback: when parent background is painted inside child OnPaint event it erases all the other same controls already painted. The picture below shows the result. Colored areas are the child controls content.

I also tried to give the responsibility to draw connectors to Surface and add child controls to Surface.Controls list.
The drawback: child control are always drawn on top of my custom drawing (which happens in Surface.OnPaint), because their painting happens somewhen later in the queue.

My requirements are:
I need workable controls inside my Surface (receiving any mouse and keyboard event, focusable, etc). Every control would have some custom-drawn connectors to show context on surface. And when controls are overlapped I want everything to appear in expected order.
How to achieve this?
I found simple solution to my problem.
I’ve just used Region property of child control (popup) to setup clipping path:
I didn’t know about custom path clipping before.