C# GDI进行Button重绘

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 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值