Change backcolor when controls are disable

Posted on 2006-03-27
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

    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

    You can change the backgrounds by using the .BackColor method.  

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

    Accepted Solution

    see an article I wrote in July 2005 at
    LVL 5

    Expert Comment

    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.
    LVL 8

    Author Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now