Setting the parent of a usercontrol prevents it from being transparent

前端 未结 1 1267
旧时难觅i
旧时难觅i 2021-01-13 05:15

I\'ve created a simple user control which is manually created with something like

MyUserControl ctrl = new MyUserControl();

The control hav

1条回答
  •  鱼传尺愫
    2021-01-13 05:36

    Windows Forms doesn't really support transparent controls.
    You can work around this limitation by overriding the CreateParams property of the control and setting a custom style (look it up on google).
    Further you have to override the painting of your control so that not only your control but also the parent control is redrawn. The reason is that the background must be painted before your control paints itself.
    Finally you should override the OnPaintBackground method, as you have done, to make sure no background is painted.

    Quite clumsy, and not perfect, but it should work.

    0 讨论(0)
提交回复
热议问题