Solved

Changing disabled text color

Posted on 2004-10-18
3
387 Views
Last Modified: 2010-05-03
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
Comment
Question by:plesage
3 Comments
 
LVL 19

Expert Comment

by:Shauli
ID: 12342065
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
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 12343188
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
 
LVL 1

Author Comment

by:plesage
ID: 12348188
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now