Marco,
First, you would change your code to this:
((TextBox) sender).BackColor = Color.Red;
Then, on your form, you would cycle through all the TextBox controls
(the Controls collection will help you with this, just use the as operator
to determine if the control is a textbox) and then attach that method to the
Enter event handler.
You might want to make sure you attach another event handler to change
the color back when the textbox loses focus.
--
- Nicholas Paldino [.NET/C# MVP]
-
(E-Mail Removed)
"Marco Pais" <marco.pais[at]gmail.com> wrote in message
news:(E-Mail Removed)...
> Hi there.
>
> How can I change the background color of a textbox when it gets the focus?
>
> I can handle the "Enter" event and do this
> private void txtDummie_Enter(object sender, EventArgs e) {
>
> txtDummie.BackColor=Color.Red;
>
> }
>
> But how can I use this code to work with all textboxes in form? How can I
> use "sender" argument?
>
> Thanks in advance.
>
> Regards,
>
> Marco
>
>