winfrom 重绘checkbox 使前面的选着框变大
请问这个怎么做啊。
我在网上下了一份示例性的代码
还重写了里面的事件,我可以不重写吗?
OnPaint()方法不是太懂。
我在网上下了一份示例性的代码
public class SkinCheckBox:CheckBox
{
private State state=State.Normal;
public SkinCheckBox()
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = System.Drawing.Color.Transparent;
}
protected override void OnMouseEnter(EventArgs e)
{
state = State.MouseOver;
this.Invalidate();
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
state = State.Normal;
this.Invalidate();
base.OnMouseLeave(e);
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) != MouseButtons.Left) return;
state = State.MouseDown;
this.Invalidate();
base.OnMouseDown(e);
}
protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
state = State.Normal;
this.Invalidate();
base.OnMouseUp(e);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (SkinImage.checkbox.img==null)
{
base.OnPaint(e);
return;
}
int i = (int)state;
if (!this.Enabled) i = 16;
if (this.CheckState == CheckState.Checked) i+=16;
if (this.CheckState == CheckState.Indeterminate) i+=16;
Rectangle rc = this.ClientRectangle;
Rectangle r1 = rc;;
Graphics g = e.Graphics;
base.OnPaint(e);
int cw = SystemInformation.MenuCheckSize.Width ;
if (this.CheckAlign == ContentAlignment.MiddleLeft)
{
r1=Rectangle.FromLTRB(0,(r1.Height-cw)/2,0+cw,(r1.Height+cw)/2);
}
else
{
r1=Rectangle.FromLTRB(r1.Right-cw-1,(r1.Height-cw)/2,r1.Right,(r1.Height+cw)/2);
}
SkinDraw.DrawRect1(g,SkinImage.checkbox,r1,i);
}
}
还重写了里面的事件,我可以不重写吗?
OnPaint()方法不是太懂。
...全文
相关推荐
DataGridView表头添加checkbox实现全选反选
DataGridView表头添加checkbox实现全选反选
C# winfrom 在窗体中怎么实现勾选checkbox删除图片
在winfrom窗体里实现的一个小例子 勾选checkbox删除图片,支持多选
winfrom DataGridView绘制列头CheckBox
手动绘制winfrom DataGridView的列头CheckBox 实现单击列头的CheckBox全选和不全选!
C#TreeView形式的ComboBox可使用CheckBox
ComboBox,下拉框中显示的是TreeView,适用于下拉菜单为树状结构,使用C#,Windows Form,有应用实例。
winfrom控件知识总结
winfrom控件知识总结


