Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting combobox list forecolor? 1

Status
Not open for further replies.

swk003

IS-IT--Management
Feb 10, 2004
86
GB
Does anyone have any quick code which will set combobox list items (3 items) to different colors. I want to set the following: index 0 = white, index 1 = yellow and index 2 = pink. I'm sure this is fairly simple just can't suss it out....
 
Set DrawMode to one of the OwnerDraw values and then play with:

Code:
  Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem

    e.DrawBackground()
    Dim backbrsh As Brush
    Dim forebrsh As Brush = Brushes.Black
    Dim rect As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
    Select Case e.Index
      Case 0
        backbrsh = Brushes.White
      Case 1
        backbrsh = Brushes.Yellow
      Case 2
        backbrsh = Brushes.Pink
      Case Else
        backbrsh = Brushes.Green
    End Select
    e.Graphics.FillRectangle(backbrsh, rect)
    e.Graphics.DrawString(ComboBox1.Items(e.Index).ToString, e.Font, forebrsh, rect)

  End Sub

Hope this helps.

[vampire][bat]
 
This worked great! Sorry for the delayed reply. Thanks again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top