Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

Changing disabled text color

There is this very big old VB application that I've been asked to convert to XP and there is a lot in there. In it, they put gray color in the Backcolor for all disabled objects like textbox and combobox so now with XP new color scheme, the text in it is no more readable.

I want the text to stay black even if disabled (since the backcolor is grayed when disabled), BUT I don't want to use the LOCKED solution because there is to much to change and it use a lot of Frame.enable = false, so I can't imagine to change all items status to lock in those frame.

Even if it's not possible to change the disabled text value from VB's IDE point of view, maybe there is some tricky code that will set the color to black only for this application ?

I guess I ask for miracles ...
0
plesage
Asked:
plesage
1 Solution
 
ShauliCommented:
You can leave the textbox enabled, and with a gray bacjground, and set the KeyPreview of the form to true, then add the below code to the keypress event of the form:

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim fControl As Control
For Each fControl In Me
    If TypeOf fControl Is TextBox Then
        KeyAscii = 0
    End If
Next
End Sub

This will not allow typing on one hand and leave the font color black.

S
0
 
ArkCommented:
Hi
First of all, above code will disable ALL keyboard input on form if there is at least one text box. Also, this code doesn't prevent mouse copy/paste. WinXP is smart enough to change disabled text color itself according to background color of edit control. Just set this backcolor manually:

Private Sub Form_Load()
Dim fControl As Control
For Each fControl In Me
    If TypeOf fControl Is TextBox Then
        fControl.BackColor = vbGrayText
    End If
Next
End Sub

And you'll see black text
0
 
plesageAuthor Commented:
Hey thank you !

That is a very good answer for me. It will save me a lot of trouble. So now, everywhere control are disabled, I can put it backColor to vbGrayText.

In fact, vbGrayText represent the exact color of disabled text ( depending of each color scheme ) so as you said, XP is "smart" enough to use the black ForeColor when the BackColor is vbGrayText.

For people who want to use the hex value of vbGrayText : &H80000011  

Here is other usefull value like that (http://www.cpcug.org/user/clemenzi/technical/Languages/Colors.htm) :

vbScrollBars           &H80000000  Scroll-bars gray area
vbDesktop              &H80000001  Desktop
vbActiveTitleBar       &H80000002  Active window caption
vbInactiveTitleBar     &H80000003  Inactive window caption
vbMenuBar              &H80000004  Menu background
vbWindowBackground     &H80000005  Window background
vbWindowFrame          &H80000006  Window frame
vbMenuText             &H80000007  Text in menus
vbWindowText           &H80000008  Text in windows
vbTitleBarText         &H80000009  Text in caption, size box, scroll-bar arrow box
vbActiveBorder         &H8000000A  Active window border
vbInactiveBorder       &H8000000B  Inactive window border
vbApplicationWorkspace &H8000000C  Background color of multiple document interface (MDI) applications
vbHighlight            &H8000000D  Items selected item in a control
vbHighlightText        &H8000000E  Text of item selected in a control
vbButtonFace           &H8000000F  Face shading on command buttons
vbButtonShadow         &H80000010  Edge shading on command buttons
vbGrayText             &H80000011  Grayed (disabled) text
'   Set to 0 if the current display driver
'   does not support a solid gray color
vbButtonText           &H80000012  Text on push buttons
vbInactiveCaptionText  &H80000013  Color of text in an inactive caption
vb3DHighlight          &H80000014  Highlight color for 3D display elements
vb3DDKShadow           &H80000015  Darkest shadow color for 3D display elements
vb3DLight              &H80000016  Second lightest of the 3D colors after vb3Dhighlight
vb3DFace               &H8000000F  Color of text face
vb3Dshadow             &H80000010  Color of text shadow
vbInfoText             &H80000017  Color of text in ToolTips
vbInfoBackground       &H80000018  Background color of ToolTips

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now