博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Button MouseEvent颜色变化
阅读量:4318 次
发布时间:2019-06-06

本文共 1101 字,大约阅读时间需要 3 分钟。

public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();             this.button1.Enter += button_Enter;            this.button1.Leave += button_Leave;             this.button2.Enter += button_Enter;            this.button2.Leave += button_Leave;             //继续写其他的        }         void button_Leave(object sender, EventArgs e)        {            (sender as Button).BackColor = SystemColors.Control;        }         void button_Enter(object sender, EventArgs e)        {            (sender as Button).BackColor = Color.Red;        }    }

 

//给每个按钮全部订阅一样的点击事件button1.Click += button_Click;button2.Click += button_Click;button3.Click += button_Click;private void button_Click(object sender, EventArgs e){    Button[] btnArr = { button1, button2,button3 };    Button btn = sender as Button;//当前按钮    btn.BackgroundImage = Resource1.backImg1;//将当前按钮背景设为backImg1,Resource1是资源文件类名    //剩下的除当前按钮外,全部设另一个背景    Array.ForEach(btnArr.Where(p => p != btn).ToArray(), p => p.BackgroundImage = Resource1.backImg2);}

 

转载于:https://www.cnblogs.com/XACOOL/p/5606602.html

你可能感兴趣的文章
3选择结构程序设计
查看>>
Python学习 12day__高级语法
查看>>
关于做产品的一点思考
查看>>
超大地形的处理 (Terrain Visualization)【转自知乎】
查看>>
html知识2
查看>>
Python—面向对象01
查看>>
Android DDMS ADB Hierarchy Viewer Lint
查看>>
Linux命令学习(5):more和less
查看>>
Linux 三剑客之sed命令总结
查看>>
倒计时
查看>>
36.Altium Designer(Protel)网络连接方式Port和Net Label详解
查看>>
读《分布式一致性原理》CURATOR客户端3
查看>>
iOS 虚拟机测试出现的相关问题
查看>>
MySQL crash-safe replication(3): MySQL的Crash Safe和Binlog的关系
查看>>
mac 无法打开xx ,因为无法确认开发者身份
查看>>
简单的排序算法(冒泡、选择、插入)
查看>>
[剑指Offer] 11.二进制中1的个数
查看>>
重置报表输出选择
查看>>
ip代理池抓取qq音乐热歌前300
查看>>
Android面试题集合
查看>>