我创建了一个自定义checkBox
来增加checkbox
. 我已经覆盖了OnPaint method
下面给出的。当我使控件透明时,背景变为白色,而不是透明。可能是什么问题?
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
int h = this.Height;
if (BackColor == Color.Transparent)
{
pevent.Graphics.Clear(this.Parent.BackColor);
}
else
{
pevent.Graphics.Clear(BackColor);
}
Rectangle rc = new Rectangle(new Point(0, 0), new Size(h, h));
ControlPaint.DrawCheckBox(pevent.Graphics, rc,
this.Checked ? ButtonState.Checked : ButtonState.Normal);
SizeF stringMeasure = pevent.Graphics.MeasureString(Text, Font);
int topOffset = (int)(ClientRectangle.Height - stringMeasure.Height) / 2;
pevent.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), this.Height, topOffset);
}