arcross
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?
There might be an easier solution, but you can override the Paint event, and paint it depending on your enabled status.
You can change the backgrounds by using the .BackColor method.
TextBox1.BackColor = Color.White
ComboBox1.BackColor = Color.White
TextBox1.BackColor = Color.White
ComboBox1.BackColor = Color.White
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Private Sub txtmyBox_EnabledChanged(By Val 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.
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.
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!
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!