"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