public partial class ButtonEx : Button
{
public ButtonEx() {
//首先开启双缓冲,防止闪烁
//双缓冲的一大堆设置 具体参数含义参照msdn的ControlStyles枚举值
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
}
//用来标示是否鼠标正在悬浮在按钮上 true:悬浮在按钮上 false:鼠标离开了按钮
private bool m_bMouseHover;
//用来标示是否鼠标点击了按钮 true:按下了按钮 false:松开了按钮
private bool m_bMouseDown;
//重载鼠标悬浮的事件
protected override void OnMouseEnter(EventArgs e) {
//当鼠标进入控件时,标示变量为进入了控件
m_bMouseHover = true;
//刷新面板触发OnPaint重绘
this.Invalidate();
base.OnMouseEnter(e);
}
//重载鼠标离开的事件
protected override void
C# GDI进行Button重绘
最新推荐文章于 2024-09-04 16:11:45 发布