|
I have a form that has an array of text boxes dynamically added to a splitcontainer on a form. I use the same array to add text boxes to the form twice (different data for different table). I would like to use an event handler, preferably once, to change background color to yellow when textbox[i] receives focus, and back to white when it loses focus. I am currently going around in circles. Can anyone help me? Thanks for your input
Everett
|
|
|
|
|
Add in a lambda, at the point where you create the textboxes. Like the example below;
public Form1()
{
InitializeComponent();
var tb = new TextBox();
tb.GotFocus += delegate (object s, EventArgs a)
{
(s as TextBox).BackColor = Color.Red;
};
tb.LostFocus += delegate(object s, EventArgs a)
{
(s as TextBox).BackColor = Color.Green;
};
Controls.Add(tb);
}
|
|
|
|
|
hi, your idea is right, but the textbox has't the event GotFocus & LostFocus, instead of, has the event Enter & Leave.
|
|
|
|
|
Works beeeautiful. Thank you so much Eddy
Everett
|
|
|
|