2013-01-02 47 views
0

我需要更改焦点上的BackColor按钮。
现在我正在使用MouseOverBackColor < = 在一个按钮。
当我通过鼠标对按钮进行对焦时,其背景颜色更改为银色
当我通过tab键或.focus()从后面的代码集中按钮时,我想将它的背景颜色更改为Silver
我应该使用哪个事件?
有人可以帮我吗? 谢谢。更改窗口焦点时按钮的BackColor

回答

0

您可以使用GotFocusLostFocusEnterLeave事件来实现此目的。

private void myBtn_GotFocus(object sender, EventArgs e) 
{ 
    myBtn.BackColor = Color.Silver; 
} 

private void myBtn_LostFocus(object sender, EventArgs e) 
{ 
    myBtn.BackColor = SystemColors.Control; 
} 
1

为了保持一致,你可以同时拥有tabmouseover更改按钮的颜色,当焦点在窗体上。

但是您需要覆盖低级Got,LostFocus事件。

protected override void OnLostFocus(EventArgs e) 
{ 
    base.OnLostFocus(e); 
} 

protected override void OnGotFocus(EventArgs e) 
{ 
    base.OnGotFocus(e); 
} 

Reference