• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5278
  • Last Modified:

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.
0
dbbishop
Asked:
dbbishop
  • 2
1 Solution
 
TimCotteeCommented:
Hi dbbishop,

No it is not possible as such, though you can subclass the control and deal with it there. The simplest way of doing the same thing is to use the .Locked property of a textbox rather than the .enabled property. This retains any formatting such as font color but prevents editing of the contents. You can still select and copy the contents of a locked control though. Not all controls support this property but the textbox certainly does.

Tim Cottee
0
 
vb_elmarCommented:
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
0
 
vb_elmarCommented:
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
0
 
dbbishopAuthor Commented:
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now