Button MouseEvent颜色变化
Posted 小A永不败
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Button MouseEvent颜色变化相关的知识,希望对你有一定的参考价值。
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); }
以上是关于Button MouseEvent颜色变化的主要内容,如果未能解决你的问题,请参考以下文章