PDA

View Full Version : Overrule ForeColor of disabled textbox



Thymen
02-25-2006, 05:19 AM
Hi folks,

if I set the option Enabled of a control on a form to False, then the text get's greyed out. Instead of greying out the forecolor I want to change the backcolor, and that works fine. But how to change the ForeColor of a disabled control to vbBlack? It appears the Enable setting overrules that...

For Each Ctrl In Userform1.Controls
If (TypeOf Ctrl Is MSForms.TextBox) Or (TypeOf Ctrl Is MSForms.CheckBox) Then
Ctrl.Enabled = False
If (TypeOf Ctrl Is MSForms.TextBox) Then
Ctrl.BackColor = &H80000018
Ctrl.ForeColor = vbBlack
End If
End If
Next Ctrl
Here, Ctrl.ForeColor = vbBlack has no effect

Regards,
Thymen

XLGibbs
02-25-2006, 08:41 AM
As an alternative, can you just toggle their locked property? that way you can maintain control of their colors...if they are locked they can't be changed...

I am not sure if you can change the forecolor if disabled.....I usually do the locked/unlocked or visible/hidden toggles instead of worrying about the font color..

Thymen
02-25-2006, 09:16 AM
XLGibbs,
can do, yes. But that means that tabbing/selecting through the controls also tabs through the locked controls. I prefer that they be skipped. If I cannot figure out how to change the forecolor of a disabled control, I wil either live with the color it gives, or choose locked instead of Enabled = False
Thymen

XLGibbs
02-25-2006, 09:41 AM
Well, there may be a way...

I guess it would depend on how many you had, but you could just change the tab order property on change events...

It is more clear to the user if the color changes identifying it is disabled anyway, so not sure of the benefit of changing it to look the same...