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;
}
}
打开属性面板,如上图设置backcolor=初始化颜色
再者你都能代码点出button了么,为何不初始化button.backcolor=来设置,
是在用VS编辑吗,还初始化注册事件,没视图编辑器吗,不清楚什么个情况的说
上面说的给button BackColor,触发button click(Event e, ......)的时候 给button BackColor设置新的颜色值,思路有,不难实现。
button1.BackColor = Control.DefaultBackColor;//使控件button1恢复默认背景色