472,119 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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

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
2 15207
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
"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.

Similar topics

5 posts views Thread by Mały Piotruś | last post: by
2 posts views Thread by Don | last post: by
6 posts views Thread by =?Utf-8?B?S2Fp?= | last post: by
6 posts views Thread by =?Utf-8?B?Sm9obiBBdXN0aW4=?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.