Changeing fore color of disabled combo box

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

our form, when it is in read only mode has about 10 combo boxes on it, and a
bunch of text boxes, now the text box has a read only property which makes
the text black, but the combo box doesn't so we have to disable it to make
it "readonly" but the text is gray on gray... which is hard to read for some
people. Is there any way to make the combo boxes forecolor black to match
the textbox's forecolor when its read only? thanks
 
Brian,
I don't think there is any color that will not appear grayed. If it were a
TextBox, you could make it readonly, but the combo does not have such a
property. Set the font to Bold makes it more readable and if you don't want
it bold when enabled, un bold it.

That's the best I can think of.
HTH
Les Smith
http://www.KnowDotNet.com
 
Brian,
Create you own control inherited from ComboBox

<ToolboxBitmap(GetType(System.Windows.Forms.ComboBox))> _
Public Class ReadOnlyComboBox
Inherits System.Windows.Forms.ComboBox

Private m_ReadOnly As Boolean = False
Public Event ReadOnlyChanged As EventHandler

<Category("Behavior"), DefaultValue(False), Bindable(True), _
Description("Controls whether text in the control can be changed")> _
Public Property [ReadOnly]() As Boolean
'Gets of sets the ReadOnly flag
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
'Check if the color was changed
If m_ReadOnly <> Value Then
m_ReadOnly = Value
OnReadOnlyChanged()
End If
End Set
End Property

Protected Overridable Sub OnReadOnlyChanged()
MyBase.TabStop = Not m_ReadOnly
'Raise event
RaiseEvent ReadOnlyChanged(Me, New EventArgs())
End Sub

Public Overrides Function PreProcessMessage(ByRef msg As Message) As Boolean
'Prevent keyboard entry if control is ReadOnly
If m_ReadOnly = True Then
'Check if its a keydown message
If msg.Msg = &H100 Then
'Get the key that was pressed
Dim key As Int32 = msg.WParam.ToInt32
'Ignore navigation keys
If key = Keys.Tab Or key = Keys.Left Or key = Keys.Right Then
'Do nothing
Else
Return True
End If
End If
End If
'Call base method so delegates receive event
Return MyBase.PreProcessMessage(msg)
End Function

Protected Overrides Sub WndProc(ByRef m As Message)
'Prevent list displaying if ReadOnly
If m_ReadOnly = True Then
If m.Msg = &H201 OrElse m.Msg = &H203 Then
Return
End If
End If
'Call base method so delegates receive event
MyBase.WndProc(m)
End Sub

Stephen
 
thanks

Stephen Muecke said:
Brian,
Create you own control inherited from ComboBox

<ToolboxBitmap(GetType(System.Windows.Forms.ComboBox))> _
Public Class ReadOnlyComboBox
Inherits System.Windows.Forms.ComboBox

Private m_ReadOnly As Boolean = False
Public Event ReadOnlyChanged As EventHandler

<Category("Behavior"), DefaultValue(False), Bindable(True), _
Description("Controls whether text in the control can be changed")> _
Public Property [ReadOnly]() As Boolean
'Gets of sets the ReadOnly flag
Get
Return m_ReadOnly
End Get
Set(ByVal Value As Boolean)
'Check if the color was changed
If m_ReadOnly <> Value Then
m_ReadOnly = Value
OnReadOnlyChanged()
End If
End Set
End Property

Protected Overridable Sub OnReadOnlyChanged()
MyBase.TabStop = Not m_ReadOnly
'Raise event
RaiseEvent ReadOnlyChanged(Me, New EventArgs())
End Sub

Public Overrides Function PreProcessMessage(ByRef msg As Message) As Boolean
'Prevent keyboard entry if control is ReadOnly
If m_ReadOnly = True Then
'Check if its a keydown message
If msg.Msg = &H100 Then
'Get the key that was pressed
Dim key As Int32 = msg.WParam.ToInt32
'Ignore navigation keys
If key = Keys.Tab Or key = Keys.Left Or key = Keys.Right Then
'Do nothing
Else
Return True
End If
End If
End If
'Call base method so delegates receive event
Return MyBase.PreProcessMessage(msg)
End Function

Protected Overrides Sub WndProc(ByRef m As Message)
'Prevent list displaying if ReadOnly
If m_ReadOnly = True Then
If m.Msg = &H201 OrElse m.Msg = &H203 Then
Return
End If
End If
'Call base method so delegates receive event
MyBase.WndProc(m)
End Sub

Stephen


Brian Henry said:
our form, when it is in read only mode has about 10 combo boxes on it,
and
a
bunch of text boxes, now the text box has a read only property which makes
the text black, but the combo box doesn't so we have to disable it to make
it "readonly" but the text is gray on gray... which is hard to read for some
people. Is there any way to make the combo boxes forecolor black to match
the textbox's forecolor when its read only? thanks
 
Back
Top