Link to home
Start Free TrialLog in
Avatar of arcross
arcrossFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Change backcolor when controls are disable

Hi, how can i change the background color of a textbox and combox when they are disable?
Avatar of PockyMaster
PockyMaster
Flag of Netherlands image

There might be an easier solution, but you can override the Paint event, and paint it depending on your enabled status.
Avatar of ZeonFlash
ZeonFlash

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

TextBox1.BackColor = Color.White
ComboBox1.BackColor = Color.White
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of arcross

ASKER

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!