hello
how to change background color of textbox
but on focus event
i.e in window form has two textbox and courser on the textbox1 then change bgcolor then press enter and go to next textbox2 and change color of textbox2
but how to get focus event on textbox both
please help
Loading

Lalit MPosted Nov 18, 2009, 7:59 AM
$(':text').hover(function() { this.style.backgroundColor = "#BCFFB9" }, function() { this.style.backgroundColor = "transparent" });
Purushottam RathorePosted Nov 18, 2009, 7:33 AM
Use two TextBox and one button on the form in window application and write the following line of code on Form.cs.
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Focus();
textBox1.BackColor = System.Drawing.Color.Red;
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Focus();
textBox2.BackColor = System.Drawing.Color.Yellow;
}
Nilanka DharmadasaPosted Nov 18, 2009, 7:22 AM
You can use Enter event for this. And also if you want to change the color of first text box to the default color when you go to the next text box, that can be done with leave event.
Use this code.
private void textBox_Enter(object sender, EventArgs e)
{
TextBox a = (TextBox)sender;
a.BackColor = Color.Blue;
}
private void textBox_Leave(object sender, EventArgs e)
{
TextBox a = (TextBox)sender;
a.BackColor = SystemColors.Window;
}
Bind those events to the two text boxes. (You can even do this from the designer without writing code.)
public Form1()
{
InitializeComponent();
this.textBox1.Leave += new System.EventHandler(this.textBox_Leave);
this.textBox1.Enter += new System.EventHandler(this.textBox_Enter);
this.textBox2.Leave += new System.EventHandler(this.textBox_Leave);
this.textBox2.Enter += new System.EventHandler(this.textBox_Enter);
}
If you find this answer useful, please mark this as accepted.