| 12
 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
 
 | Imports Microsoft.VisualBasic
Public Class ComboIcone
    Inherits System.Windows.Forms.ComboBox
    Public ListaImg1 As New Windows.Forms.ImageList
    'It is the ImageList associated to the Combo
 
    Public Sub New()
        DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
        'Set the DrawMode to OwnerDraw
    End Sub
 
    Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
        e.DrawBackground()
        e.DrawFocusRectangle()
        Dim item As New ComboBoxIconItem
        Dim imageSize As New Drawing.Size
        imageSize = ListaImg1.ImageSize
        Dim bounds As New Drawing.Rectangle
        bounds = e.Bounds
        Try
            item = Me.Items(e.Index)
            If (item.ImageIndex <> -1) Then
                Me.ListaImg1.Draw(e.Graphics, bounds.Left, _
                    bounds.Top, item.ImageIndex)
                e.Graphics.DrawString(item.Text, e.Font, _
                    New Drawing.SolidBrush(e.ForeColor), bounds.Left + _
                    imageSize.Width, bounds.Top)
            Else
                e.Graphics.DrawString(item.Text, e.Font, _
                    New Drawing.SolidBrush(e.ForeColor), bounds.Left, _
                    bounds.Top)
            End If
        Catch ex As Exception
            If (e.Index <> -1) Then
                e.Graphics.DrawString(Items(e.Index).ToString(), e.Font, _
                    New Drawing.SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
            Else
                e.Graphics.DrawString(Text, e.Font, _
                    New Drawing.SolidBrush(e.ForeColor), bounds.Left, bounds.Top)
            End If
        End Try
        MyBase.OnDrawItem(e)
    End Sub
 
End Class
Public Class ComboBoxIconItem
    Private _text As String
 
    Property Text() As String
        Get
            Return _text
        End Get
        Set(ByVal Value As String)
            _text = Value
        End Set
    End Property
 
    Private _imageIndex As Integer
 
    Property ImageIndex() As Integer
        Get
            Return _imageIndex
        End Get
 
        Set(ByVal Value As Integer)
            _imageIndex = Value
        End Set
    End Property
 
    Public Sub New()
        _text = ""
    End Sub
 
    Public Sub New(ByVal text As String)
        _text = text
    End Sub
 
    Public Sub New(ByVal text As String, ByVal imageIndex As Integer)
        _text = text
        _imageIndex = imageIndex
    End Sub
 
 
    Public Overrides Function ToString() As String
        Return _text
    End Function
End Class |