Link to home
Start Free TrialLog in
Avatar of D B
D BFlag for United States of America

asked on

Changing Font Color of Disabled control

Does anyone know how (if it is possible) to change the font color (forecolor) of a disabled control (vb6). As you know, when the enabled property of a control (textbox) is set to False, the font color is gray. I would like it to remain black. I would think that if this is possible it is probably through SendMessage but do not know what message to send.
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This code makes a 'snapshot' of the command1 button, stores the
image in a picturebox and fills the 'Command1.DisabledPicture' property
with the 'picture1.image'.


Needs:
=====
1 CommandButton (set Command1.Style to '1' at design time)
1 Picturebox




Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" _
                                    (ByVal hDestDC As Long, _
                                     ByVal x As Long, _
                                     ByVal y As Long, _
                                     ByVal nWidth As Long, _
                                     ByVal nHeight As Long, _
                                     ByVal hSrcDC As Long, _
                                     ByVal xSrc As Long, _
                                     ByVal ySrc As Long, _
                                     ByVal dwRop As Long) As Long



Private Sub disableCOMMAND1()
    Command1.Caption = ""
    Command1.Enabled = 0
End Sub



Private Sub Command1_Click()
    disableCOMMAND1
End Sub



Private Sub Form_Activate()
    DoEvents
    Dim A As Long
    Dim s As Long
    Picture1.AutoRedraw = True
    Picture1.Width = Command1.Width + 60: Picture1.Height = Command1.Height + 60
    s = GetDC(Command1.hwnd)
    BitBlt Picture1.hDC, 0, 0, Command1.Width, Command1.Height, s, 0, 0, vbSrcCopy
    Picture1.Refresh
    Set Command1.DisabledPicture = Picture1.Image
End Sub
This code makes a 'snapshot' of the Text1 textbox, stores the
image in a picturebox and overlaps the (disabled) textbox
with the picturebox.


Needs:
=====
1 CommandButton
1 Picturebox
1 Textbox



Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" _
                                    (ByVal hDestDC As Long, _
                                     ByVal x As Long, _
                                     ByVal y As Long, _
                                     ByVal nWidth As Long, _
                                     ByVal nHeight As Long, _
                                     ByVal hSrcDC As Long, _
                                     ByVal xSrc As Long, _
                                     ByVal ySrc As Long, _
                                     ByVal dwRop As Long) As Long



Private Sub disableCOMMAND1()
    Picture1.Move Text1.Left, Text1.Top, Text1.Width, Text1.Height
    Picture1.ZOrder 0
    Command1.Caption = ""
End Sub



Private Sub Command1_Click()
    disableCOMMAND1
End Sub



Private Sub Form_Activate()
    DoEvents
    t = Timer: While Timer - t < 1: Wend
    Command1.Caption = "Move PictureBox to Text1_position"
    Dim A As Long
    Dim s As Long
    Picture1.AutoRedraw = True
    Picture1.Width = Text1.Width + 0: Picture1.Height = Text1.Height + 0
    s = GetDC(Text1.hwnd)
    BitBlt Picture1.hDC, 0, 0, Text1.Width, Text1.Height, s, 0, 0, vbSrcCopy
    Picture1.Refresh
    Text1.Enabled = 0: Text1 = "This is text1 disabled"
   
End Sub
Avatar of D B

ASKER

Thanks for the quick response.

vb_elmar: That is WAY too much work. I have a tab control with 6 tabs and about 50 TextBoxes. Even though I can iterate through the forms controls and identify the textboxes and load pictureboxes by defining one as a control array, I do not want to lock up the application creating and destroying and making all those API calls. Thanks anyway for the effort.