By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,302 Members | 3,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,302 IT Pros & Developers. It's quick & easy.

Changeing fore color of disabled combo box

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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 Henry" <br**********@newsgroups.nospam> wrote in message
news:O8*************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2

P: n/a
Brian,
Create you own control inherited from ComboBox

<ToolboxBitmap(GetType(System.Windows.Forms.ComboB ox))> _
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" <br**********@newsgroups.nospam> wrote in message
news:O8*************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #3

P: n/a
thanks

"Stephen Muecke" <st*****@senet.com.au> wrote in message
news:Of**************@TK2MSFTNGP09.phx.gbl...
Brian,
Create you own control inherited from ComboBox

<ToolboxBitmap(GetType(System.Windows.Forms.ComboB ox))> _
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" <br**********@newsgroups.nospam> wrote in message
news:O8*************@TK2MSFTNGP09.phx.gbl...
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


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.