0
我創建了一個自定義checkBox
來增加checkbox
的矩形的高度。我已經覆蓋下面給出的OnPaint method
。當我使控件透明時,背景變成白色,而不是透明。可能是什麼問題?OnPaint Paint Issue
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);
}
你是什麼意思「使控制透明」?我試圖設置背景顏色trasnparant,但一切工作正常。 – 2013-02-21 11:47:26