Solved

Changing disabled text color

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 340
Run code from text file in vb 1 87
Access 2013 combo box not working 3 60
Advice in Xamarin 21 109
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

730 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