1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
Imports System.Windows.Forms
Imports System.Drawing
''' <summary>
''' Da es im Framework keine ImageComboBox gibt hatte ich einfach selber
''' eine geschrieben bzw. die vorhandene ComboBox erweitert.
''' Achtung: Man kann nur Items per Code hinzufügen also nicht im Designer,
''' da man im Designer kein ImageKey festlegen kann.
''' </summary>
''' <remarks>Tim Hartwig</remarks>
Public Class ImageComboBox
Inherits ComboBox
Private mImageList As ImageList = Nothing
Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
End Sub
Public Property ImageList() As ImageList
Get
Return mImageList
End Get
Set(ByVal value As ImageList)
mImageList = value
End Set
End Property
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
MyBase.OnDrawItem(e)
e.DrawBackground()
e.DrawFocusRectangle()
If e.Index >= 0 Then
If TypeOf Me.Items(e.Index) Is ImageComboItem Then
If mImageList IsNot Nothing Then
Dim CurrItem As ImageComboItem = DirectCast(Me.Items(e.Index), ImageComboItem)
If CurrItem.ImageIndex <> -1 Then
Me.ImageList.Draw(e.Graphics, e.Bounds.Left, e.Bounds.Top, CurrItem.ImageIndex)
e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, _
New SolidBrush(CurrItem.ForeColor), _
e.Bounds.Left + mImageList.ImageSize.Width, e.Bounds.Top)
Else
e.Graphics.DrawString(CurrItem.Text, CurrItem.Font, _
New SolidBrush(CurrItem.ForeColor), _
e.Bounds.Left + mImageList.ImageSize.Width, e.Bounds.Top)
End If
End If
Else
e.Graphics.DrawString(Me.Items(e.Index).ToString(), e.Font, _
New SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Top)
End If
End If
End Sub
End Class
Public Class ImageComboItem
Private mForeColor As Color = Color.Black
Private mImageIndex As Integer = -1
Private mTag As Object = Nothing
Private mText As String = ""
Private mFont As Font
Sub New(ByVal Text As String, ByVal Font As Font, ByVal ForeColor As Color)
mText = Text
mFont = Font
mForeColor = ForeColor
End Sub
Sub New(ByVal Text As String, ByVal Font As Font, _
ByVal ForeColor As Color, ByVal ImageIndex As Integer)
mText = Text
mFont = Font
mForeColor = ForeColor
mImageIndex = ImageIndex
End Sub
Public Property ForeColor()
Get
Return mForeColor
End Get
Set(ByVal value)
mForeColor = value
End Set
End Property
Public Property ImageIndex() As Integer
Get
Return mImageIndex
End Get
Set(ByVal value As Integer)
mImageIndex = value
End Set
End Property
Public Property Tag() As Object
Get
Return mTag
End Get
Set(ByVal value As Object)
mTag = value
End Set
End Property
Public Property Text() As String
Get
Return mText
End Get
Set(ByVal value As String)
mText = value
End Set
End Property
Public Property Font() As Font
Get
Return mFont
End Get
Set(ByVal value As Font)
mFont = value
End Set
End Property
Public Overrides Function ToString() As String
Return mText
End Function
End Class
|