Control is disabled, but not dimmed

K

Kristi

I have a userform with a checkbox and a text box. If the checkbox is not
checked, I want the adjacent text box to be disabled and dimmed. When the
box is checked, I want the text box to become enabled. I thought coding the
text box as disabled automatically made the box dimmed, but it is not
working. My code is below. The text is disabled as desired in the sense
that you cannot edit it, but it is not dimmed. What's wrong?

Private Sub chkEnclosure_Click()
If chkEnclosure = "True" Then
cmbEnclosure.Enabled = True
Else
cmbEnclosure.Enabled = False
End If
End Sub
 
J

Jonathan West

That is how textboxes work. If you want it to look dimmed when disabled, set
the ForeColor to some suitable shade of grey. at the same time as you
disable it.
 
J

Jean-Guy Marcil

Kristi was telling us:
Kristi nous racontait que :
I have a userform with a checkbox and a text box. If the checkbox is
not checked, I want the adjacent text box to be disabled and dimmed.
When the box is checked, I want the text box to become enabled. I
thought coding the text box as disabled automatically made the box
dimmed, but it is not working. My code is below. The text is
disabled as desired in the sense that you cannot edit it, but it is
not dimmed. What's wrong?

Private Sub chkEnclosure_Click()
If chkEnclosure = "True" Then
cmbEnclosure.Enabled = True
Else
cmbEnclosure.Enabled = False
End If
End Sub

Just to add to Jonathan's comments, make sure to use one of the system color
from the drop down list in the properties pane (Such as "Button Face") so
that the disabled control will take on whatever color from whatever color
schemes the user as applied. If you use a true shade of grey using a color
but the user is using a purple/violet color schemes, the grey will look
strange....

I.e
Me.CommandButton1.ForeColor = &H80000011 'Disabled text system constant
is better than
Me.CommandButton1.ForeColor = RGB(128, 128, 128) 'Gray

To see the constant for each window part (button text, active title bar,
inactive title bar, button shadow, etc.) just select one in a control color
property and copy/paste the constant that appears in the property field
after you make a choice.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
T

Tony Strazzeri

small additional clarification about what is happening. If the textbox
has data in it you will find that it is greyed. The behaviour appears
wrong because there is no text in the control. Having said that, the
solutions suggested by Jonathan and Marcil are appropriate solutions.
Additionally you can toggle the control's backstyle between transparent
or not. In my experience this makes it clearer what state the control
is in.

Hope this helps.

Cheers
TonyS.
 
K

Kristi

That makes perfect sense about using the system color, but it doesn't seem to
work for me. When I use the constant as you suggested, the color doesn't
change as it should. But when I use the RGB, it does. Why do you think this
would happen? Here is my new code with the constants.

Private Sub chkCopies_Click()
If chkCopies = True Then
Me.txtCopies.Enabled = True
Me.txtCopies.ForeColor = &H80000014
Else
Me.txtCopies.Enabled = False
Me.txtCopies.ForeColor = &H8000000F
End If
End Sub
 
J

Jean-Guy Marcil

Kristi was telling us:
Kristi nous racontait que :
That makes perfect sense about using the system color, but it doesn't
seem to work for me. When I use the constant as you suggested, the
color doesn't change as it should. But when I use the RGB, it does.
Why do you think this would happen? Here is my new code with the
constants.

Private Sub chkCopies_Click()
If chkCopies = True Then
Me.txtCopies.Enabled = True
Me.txtCopies.ForeColor = &H80000014
Else
Me.txtCopies.Enabled = False
Me.txtCopies.ForeColor = &H8000000F
End If
End Sub

:

Just use the backcolor property instead:
Me.txtCopies.BackColor = &H80000014
instead of
Me.txtCopies.ForeColor = &H80000014

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Kristi

Works great now! Thanks, Jean-Guy!

Jean-Guy Marcil said:
Kristi was telling us:
Kristi nous racontait que :


Just use the backcolor property instead:
Me.txtCopies.BackColor = &H80000014
instead of
Me.txtCopies.ForeColor = &H80000014

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top