如何实现自定义控件背景透明
在Winform中使用了Picturebox载入一张背景图片,现在想把一个自定义控件放在这张图片上,但是自定义控件有背景颜色,如何使背景颜色透明?
using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace TransColorControl { public sealed partial class CControl : Control { #region 构造函数 public CControl() { InitializeComponent(); SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); } #endregion #region 重写属性 protected override CreateParams CreateParams { get { var result = base.CreateParams; result.ExStyle |= 0x00000020; return result; } } #endregion #region 重写方法 protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; pe.Graphics.FillPie(new SolidBrush(Color.Blue), 0, 0, 30, 30, 0, 270); } #endregion } }