?
Solved

Changing disabled text color

Posted on 2004-10-18
3
Medium Priority
?
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 28

Accepted Solution

by:
Ark earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

801 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