Solved

Changing disabled text color

Posted on 2004-10-18
3
398 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

695 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