Windows应用程序,更改焦点上的文本框BackColor [英] Windows application, change textbox BackColor on focus

查看:141
本文介绍了Windows应用程序,更改焦点上的文本框BackColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

窗体中,我需要更改焦点文本框BackColor 。我想在每个文本框或控件焦点上执行此操作。



说明:当对该文本框的textbox1 BackColor重点进行更改时现在我按标签,焦点转到下一个文本框(textbox2),现在textbox2的BackColor应该改变,textbox1 BackColor应该改回为默认颜色。



我需要回答迫切。任何人都可以帮助我吗?



在此先感谢,



Amit



  //属性声明
private System.Drawing.Color NormalColor = System.Drawing.Color.FromArgb(50,82,110);
private System.Drawing.Color FocusColor = System.Drawing.Color.FromArgb(42,65,84);

//否则在构造函数中
textBox_Username.Enter + = EnterEvent;
textBox_Password.Enter + = EnterEvent;
textBox_Username.Leave + = LeaveEvent;
textBox_Password.Leave + = LeaveEvent;

//在构造函数之外
private void EnterEvent(object sender,EventArgs e)
{
if(sender is TextBox)
((TextBox)发件人).BackColor = FocusColor;

$ b private void LeaveEvent(object sender,EventArgs e)
{
if(sender is TextBox)
((TextBox)sender).BackColor = NormalColor;
}


In windows form I need to change textbox BackColor on focus. I want to do this on every textbox or control focus.

Description:- When the focus on textbox1 BackColor of this textbox should be changed and now I press tab, focus goes to next textbox (textbox2) now the BackColor of textbox2 should be changes and textbox1 BackColor should be changed back as default color.

I need answer urgently. Can anyone help me please?

Thanks in advance,

Amit

解决方案

Behold the C# solution:

//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;
}

这篇关于Windows应用程序,更改焦点上的文本框BackColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆