Tipp 0075 ComboBox - Farbige Einträge
Autor/Einsender:
Datum:
  Klaus D. Raudszus
16.05.2005
Entwicklungsumgebung:   VB.Net 2003
Framework:   1.1
Dieser Tipp zeigt, wie man mit Hilfe einer abgeleiteten Klasse der ComboBox (Inherits) farbige Einträge erreichen kann.
 
Imports System.Drawing.Drawing2D

Public Class uComboBox
  Inherits ComboBox

  Public Sub New()
    DrawMode = DrawMode.OwnerDrawFixed
  End Sub

  Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
    Dim strText As String = CStr(Items.Item(e.Index))
    Dim brBrush As Brush

    If CBool(e.State And DrawItemState.Selected) Then
      brBrush = New LinearGradientBrush( _
            e.Bounds, Color.Blue, Color.Yellow, 0)
    Else
      If e.Index Mod 2 = 0 Then
        brBrush = New LinearGradientBrush( _
              e.Bounds, Color.Yellow, Color.Red, 0)
      Else
        brBrush = New LinearGradientBrush( _
              e.Bounds, Color.Red, Color.Yellow, 0)
      End If
    End If
    e.Graphics.FillRectangle(brBrush, e.Bounds)
    brBrush = New SolidBrush(e.ForeColor)
    e.Graphics.DrawString(strText, e.Font, brBrush, _
          e.Bounds.Left, e.Bounds.Top)
  End Sub
End Class
 
Weitere Links zum Thema
ComboBox im FlatStyle anzeigen

Windows-Version
98/SE
ME
NT
2000
XP
Vista
Win 7


Download  (7,1 kB) Downloads bisher: [ 782 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Tipps | Projekte | Tutorials | Bücherecke | VB-/VBA-Tipps | API-Referenz | Komponenten | VB.Net-Forum | VB/VBA-Forum | DirectX-Forum | Foren-Archiv | DirectX | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Montag, 23. Januar 2012