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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Verona

    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.enable d=false
    combobox.backco lor=color.white
    combobox.foreco lor=color.blue

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

    How can I make the text blue?

    Thanks in advance
    Simon



  • Rick Mogstad

    #2
    Re: ComboBox - stopping it being "greyed&qu ot; out when not enabled

    derive your own control from the combobox...


    "Simon Verona" <news@aphrodite uk.com> wrote in message
    news:Oarzx6WgFH A.3692@TK2MSFTN GP09.phx.gbl...[color=blue]
    > 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.enable d=false
    > combobox.backco lor=color.white
    > combobox.foreco lor=color.blue
    >
    > This sets it to dark grey text on a white background.
    >
    > How can I make the text blue?
    >
    > Thanks in advance
    > Simon
    >
    >
    >[/color]


    Comment

    • Kevin O'Donovan

      #3
      Re: ComboBox - stopping it being &quot;greyed&qu ot; out when not enabled

      "Simon Verona" <news@aphrodite uk.com> wrote in message
      news:Oarzx6WgFH A.3692@TK2MSFTN GP09.phx.gbl...[color=blue]
      > 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.enable d=false
      > combobox.backco lor=color.white
      > combobox.foreco lor=color.blue
      >
      > This sets it to dark grey text on a white background.
      >
      > How can I make the text blue?
      >[/color]

      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()
      InitializeCompo nent()
      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.CreateGraphi cs
      Dim p As New Pen(Color.Black , 1), b As Brush = New
      SolidBrush(Syst emColors.Contro l)
      ' 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


      Comment

      Working...