我想知道是否可以checkBox
为文本和刻度绘制自定义颜色?我听说可以通过覆盖WndProc
和使用来实现WM_PAINT
,但我没有这样做的经验。
有人可以指出我正确的方向吗?
Here is an exceptionally basic example of how you can redraw a CheckBox:
public class CustomCheckBox : CheckBox
{
public CustomCheckBox()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
if (this.Checked)
{
pevent.Graphics.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 0, 16, 16));
}
else
{
pevent.Graphics.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, 16, 16));
}
}
}
It works, but its very rough around the edges! However it does illustrate very basically how you can draw custom controls.