[Webinar] Learn how to a build a cloud-first strategyRegister Now


Change backcolor when controls are disable

Posted on 2006-03-27
Medium Priority
Last Modified: 2010-08-05
Hi, how can i change the background color of a textbox and combox when they are disable?
Question by:arcross
LVL 14

Expert Comment

ID: 16303679
There might be an easier solution, but you can override the Paint event, and paint it depending on your enabled status.
LVL 17

Expert Comment

ID: 16304919
You can change the backgrounds by using the .BackColor method.  

TextBox1.BackColor = Color.White
ComboBox1.BackColor = Color.White
LVL 70

Accepted Solution

Éric Moreau earned 500 total points
ID: 16306195
see an article I wrote in July 2005 at http://emoreau.s2i.com/

Expert Comment

ID: 16307080
Private Sub txtmyBox_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtAddress.EnabledChanged
     If txtMyBox.Enabled = False Then
          txtMyBox.BackColor = Color.Blue
     End If
End Sub

Color.Blue should be changed to whatever color you want.  The code is almost identical for the combo boxes.  To bring this up automatically, just double click your control.  By defaul the function will look like:

Private Sub txtmyBox_TextChanged....

In the upper right will be a drop down box with TextChanged in bold, drop it down and select enabled changed to convert it to the above form...  or just change it manually.  Then, the code contained in it will execute whenever the control switches from enable to disabled or from disabled to enabled.  In the above example, the If statement tells it to only execute if switching from enabled to disabled.  To go from disabled to enabled, just change the true to false.

Author Comment

ID: 16308580
The backcolor i can change it when the control is disable, (i meant the forecolor,ooops my fault!).

Emoreau, i found your article before i posted this question to see if someone came with something shorter to implement.
But i havent found anything else better than yours!.

Thanks for that article!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question