Click here to Skip to main content
16,004,924 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello guys!
i have many textboxes in a form i want to change the background color into when focus enter to a textbox and when it leaves its background color changes into silver or white

What I have tried:

i tried a lot but didn't find something good
Posted
Updated 26-Mar-19 3:18am
Comments
BillWoodruff 28-Mar-19 11:39am    
Do you want this same behavior for TextBoxes which are inside other ContainerControls, like Panels ?

1 solution

Handle the TextBox.Enter and Leave events:
private void myTextBox_Enter(object sender, EventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb != null)
        {
        tb.BackColor = Color.Silver;
        }
    }

private void myTextBox_Leave(object sender, EventArgs e)
    {
    TextBox tb = sender as TextBox;
    if (tb != null)
        {
        tb.BackColor = Color.White;
        }
    }
 
Share this answer
 
Comments
Member 13985914 26-Mar-19 9:39am    
Good if i want to give this type of color
the color code is (235, 222, 240)
OriginalGriff 26-Mar-19 9:45am    
Use this:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.color.fromrgb?view=netframework-4.7.2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900