|
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class uListBox
Inherits ListBox
Private m_Font As Font
Private m_ImageItems() As String
Public Sub New()
DrawMode = DrawMode.OwnerDrawVariable
m_Font = New Font("Arial", 10)
ItemHeight = 18
m_ImageItems = Directory.GetFiles("..\Bilder", "*.bmp")
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
MyBase.OnDrawItem(e)
Dim strText As String = CStr(Items.Item(e.Index))
Dim brBrush As Brush
Dim foreBrush As Brush
If CBool(e.State And DrawItemState.Selected) Then
brBrush = New LinearGradientBrush(e.Bounds, _
Color.CadetBlue, Color.LightGreen, _
LinearGradientMode.Horizontal)
foreBrush = New SolidBrush(Color.Blue)
Else
brBrush = New LinearGradientBrush(e.Bounds, _
Color.Chartreuse, Color.LightGreen, _
LinearGradientMode.Horizontal)
foreBrush = New SolidBrush(e.ForeColor)
End If
e.Graphics.FillRectangle(brBrush, e.Bounds)
e.Graphics.DrawString(strText, m_Font, foreBrush, _
e.Bounds.Left + 30, e.Bounds.Top)
Try
Dim newImage As Bitmap = New Bitmap(m_ImageItems(e.Index))
e.Graphics.DrawImage(newImage, e.Bounds.Left, _
e.Bounds.Top + 1, 24, e.Bounds.Height - 2)
Catch
End Try
End Sub
End Class
|
|