如何在windows标准的combox中加入自定义的item

Public Class ComboPatternClass ComboPattern
Inherits System.Windows.Forms.ComboBox


Component Designer generated code#Region " Component Designer generated code "


Public Sub New()Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()

'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
End Sub


Public Sub New()Sub New()
MyBase.New()

'This call is required by the Component Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Component overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub

#End Region

'get or set current pattern style
Private _patternstyle As System.Drawing.Drawing2D.HatchStyle

Public Property PatternStyle()Property PatternStyle() As System.Drawing.Drawing2D.HatchStyle
Get
Return _patternstyle
End Get
Set(ByVal Value As System.Drawing.Drawing2D.HatchStyle)
_patternstyle = Value
End Set
End Property



Protected Overrides Sub OnDrawItem()Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
MyBase.OnDrawItem(e)
Me.DrawMode = DrawMode.OwnerDrawFixed

If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
Dim selectBrush As New SolidBrush(Me.BackColor)
e.Graphics.FillRectangle(selectBrush, e.Bounds)
Dim selectPen As New Pen(Color.Gray)
selectPen.DashStyle = Drawing2D.DashStyle.Dash
e.Graphics.DrawRectangle(selectPen, e.Bounds)
Else
Dim selectBrush As New SolidBrush(Me.BackColor)
e.Graphics.FillRectangle(selectBrush, e.Bounds)
Dim selectPen As New Pen(Me.BackColor)
e.Graphics.DrawRectangle(selectPen, e.Bounds)
End If
' e.DrawBackground()
e.DrawFocusRectangle()

Dim myBrush As System.Drawing.Drawing2D.HatchBrush

Select Case e.Index
Case 0
'no pattern
Case 1
'BackwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, Color.Black, Me.BackColor)
Case 2
'Cross
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Color.Black, Me.BackColor)

Case 3
'DarkDownwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkDownwardDiagonal, Color.Black, Me.BackColor)

Case 4
'DarkHorizontal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkHorizontal, Color.Black, Me.BackColor)

Case 5
'DarkUpwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkUpwardDiagonal, Color.Black, Me.BackColor)
Case 6
'DarkVertical
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DarkVertical, Color.Black, Me.BackColor)
Case 7
'DashedDownwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedDownwardDiagonal, Color.Black, Me.BackColor)

Case 8
'DashedHorizontal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedHorizontal, Color.Black, Me.BackColor)

Case 9
'DashedUpwardDiagonal
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedUpwardDiagonal, Color.Black, Me.BackColor)
Case 10
'DashedVertical
myBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.DashedVertical, Color.Black, Me.BackColor)

End Select

'e.Graphics.DrawRectangle(myPen, New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
If e.Index = 0 Then
Dim myBrush1 As New SolidBrush(Color.Black)
e.Graphics.DrawString(Me.Items(e.Index), e.Font, myBrush1, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
Else
'e.Graphics.DrawLine(myPen, e.Bounds.X, e.Bounds.Y + CInt(e.Bounds.Height / 2), e.Bounds.X + e.Bounds.Width, e.Bounds.Y + CInt(e.Bounds.Height / 2))
e.Graphics.FillRectangle(myBrush, e.Bounds)

End If


End Sub



Private Sub ComboPattern_SelectedIndexChanged()Sub ComboPattern_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SelectedIndexChanged
If (Me.DropDownStyle <> ComboBoxStyle.DropDownList) Then
Me.DropDownStyle = ComboBoxStyle.DropDownList
End If

Dim currentPattern As System.Drawing.Drawing2D.HatchStyle

Select Case Me.SelectedIndex
Case 0
'no pattern, use ZigZag to instead of
currentPattern = Drawing2D.HatchStyle.ZigZag

Case 1
'BackwardDiagonal
currentPattern = Drawing2D.HatchStyle.BackwardDiagonal
Case 2
'Cross
currentPattern = Drawing2D.HatchStyle.Cross

Case 3
'DarkDownwardDiagonal
currentPattern = Drawing2D.HatchStyle.DarkDownwardDiagonal

Case 4
'DarkHorizontal
currentPattern = Drawing2D.HatchStyle.DarkHorizontal

Case 5
'DarkUpwardDiagonal
currentPattern = Drawing2D.HatchStyle.DarkUpwardDiagonal

Case 6
'DarkVertical
currentPattern = Drawing2D.HatchStyle.DarkVertical

Case 7
'DashedDownwardDiagonal
currentPattern = Drawing2D.HatchStyle.DashedDownwardDiagonal


Case 8
'DashedHorizontal
currentPattern = Drawing2D.HatchStyle.DarkHorizontal

Case 9
'DashedUpwardDiagonal
currentPattern = Drawing2D.HatchStyle.DashedUpwardDiagonal

Case 10
'DashedVertical
currentPattern = Drawing2D.HatchStyle.DashedVertical
End Select
Me.PatternStyle = currentPattern
End Sub




End Class
snapshot:
