Drawing a transparent button

后端 未结 4 1477
不知归路
不知归路 2020-11-29 07:35

I\'m trying to create a transparent button in C# (.NET 3.5 SP1) to use in my WinForms application. I\'ve tried everything to get the button to be transparent (it should show

4条回答
  •  有刺的猬
    2020-11-29 08:09

    WinForms (and underlying User32) does not support transparency at all. WinForms however can simulate transparency by using control style you provide - SupportsTransparentBackColor, but in this case all that "transparent" control does, it to allow drawing parent its background.

    ButtonBase uses some windows styles that prevent working this mechanism. I see two solutions: one is to derive your control from Control (instead of ButtonBase), and second is to use Parent's DrawToBitmap to get background under your button, and then draw this image in OnPaint.

提交回复
热议问题