在窗体我需要更改textbox BackColor on focus。我想在每个文本框或控件焦点上执行此操作。Windows应用程序,更改文本框BackColor on focus
说明: -当焦点在这个文本框TextBox1的背景色要改变,现在我按Tab键,焦点转移到下一个文本框(TextBox2中)现在TextBox2中的背景色应该是变化和TextBox1的背景色应改回作为默认颜色。
我急需回答。任何人都可以帮助我吗?
由于提前,
阿米特
在窗体我需要更改textbox BackColor on focus。我想在每个文本框或控件焦点上执行此操作。Windows应用程序,更改文本框BackColor on focus
说明: -当焦点在这个文本框TextBox1的背景色要改变,现在我按Tab键,焦点转移到下一个文本框(TextBox2中)现在TextBox2中的背景色应该是变化和TextBox1的背景色应改回作为默认颜色。
我急需回答。任何人都可以帮助我吗?
由于提前,
阿米特
在文本框的事件命名GotFocus
Private Sub TextBox1_GotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.GotFocus
textbox1.backcolor = color.red
End Sub
在文本框的事件命名LostFocus
Private Sub TextBox1_LostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.LostFocus
textbox1.backcolor = color.white
End Sub
看哪C#解决方案:
//Properties declaration
private System.Drawing.Color NormalColor = System.Drawing.Color.FromArgb(50, 82, 110);
private System.Drawing.Color FocusColor = System.Drawing.Color.FromArgb(42, 65, 84);
// Else where in the Constructor
textBox_Username.Enter += EnterEvent;
textBox_Password.Enter += EnterEvent;
textBox_Username.Leave += LeaveEvent;
textBox_Password.Leave += LeaveEvent;
// Outside the Constructor
private void EnterEvent(object sender, EventArgs e)
{
if (sender is TextBox)
((TextBox)sender).BackColor = FocusColor;
}
private void LeaveEvent(object sender, EventArgs e)
{
if (sender is TextBox)
((TextBox)sender).BackColor = NormalColor;
}
这不是紧急事宜的好地方,没有服务保证。您可以致电Microsoft支持部门。使用Enter和Leave事件。 –