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

ComboBox - stopping it being "greyed" out when not enabled

P: n/a
If I have a combobox set enabled=false then by default it will have dark
grey text on a grey background. I want it to show as blue on white. I'm
trying code such as :

combobox.enabled=false
combobox.backcolor=color.white
combobox.forecolor=color.blue

This sets it to dark grey text on a white background.

How can I make the text blue?

Thanks in advance
Simon

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
derive your own control from the combobox...
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
If I have a combobox set enabled=false then by default it will have dark
grey text on a grey background. I want it to show as blue on white. I'm
trying code such as :

combobox.enabled=false
combobox.backcolor=color.white
combobox.forecolor=color.blue

This sets it to dark grey text on a white background.

How can I make the text blue?

Thanks in advance
Simon

Nov 21 '05 #2

P: n/a
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
If I have a combobox set enabled=false then by default it will have dark
grey text on a grey background. I want it to show as blue on white. I'm
trying code such as :

combobox.enabled=false
combobox.backcolor=color.white
combobox.forecolor=color.blue

This sets it to dark grey text on a white background.

How can I make the text blue?


I needed to do something similar. We wanted the combo to look like a textbox
when locked, and all our text boxes were set to draw with a flat border when
read only. To do this I inherited from the standard combo as follows. Can't
guarantee that this will compile as is, as I've extracted it from a much
larger class, as we've modified a few other features of the combo box for
our own use.

Imports System.Windows.Forms
Public Class MyCombo
Inherits ComboBox

Private mReadOnly As Boolean

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Public Property ReadOnly() As Boolean
Get
Return mReadOnly
End Get
Set(ByVal Value As Boolean)
mReadOnly = Value
' Make the control non-editable
Me.Enabled = Not Value
' Tell the control to redraw itself when the user changes the locked
status
Me.Invalidate()
End Set
End Property

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
' When we get a redraw message, ans readonly has been set
If m.Msg = &HF And mReadOnly = True Then
Dim g As Graphics = Me.CreateGraphics
Dim p As New Pen(Color.Black, 1), b As Brush = New
SolidBrush(SystemColors.Control)
' Draw a flat black border
g.DrawRectangle(p, 0, 0, Width - 1, Height - 1)
' Fill it with a gray background
g.FillRectangle(b, 1, 1, Width - 2, Height - 2)
' Draw the combobox's displayed text inside it
g.DrawString(Me.Text, Me.Font, Brushes.Black, 3, 3)
End If
End Sub
End Class

Put this in your project and build the solution, then replace a combobox
with a mycombo, and set its readonly property to true.

Kev
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.