Public Class Form1
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles MyBase.Load
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
ListBox1.Items.Add("One")
ListBox1.Items.Add("Two")
ListBox1.Items.Add("Three")
ListBox1.Items.Add("Four")
ListBox1.Items.Add("Five")
ListBox1.Items.Add("Six")
ListBox1.Items.Add("Seven")
ListBox1.Items.Add("Eight")
ListBox1.Items.Add("Nine")
ListBox1.Items.Add("Ten")
End Sub
Private Sub ListBox1_DrawItem( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs _
) Handles ListBox1.DrawItem
Dim myBrush As Brush
Dim myBackColor As Color = Color.White
Dim myForeColor As Color = Color.Black
Dim myFont As Font
Dim itemText As String
If e.Index > -1 Then
e.DrawBackground()
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
myBackColor = Color.DarkBlue
myForeColor = Color.White
End If
myBrush = New SolidBrush(myBackColor)
e.Graphics.FillRectangle(myBrush, e.Bounds)
myBrush = New SolidBrush(myForeColor)
myFont = New Font(ListBox1.Font.Name, ListBox1.Font.Size, ListBox1.Font.Style)
itemText = (e.Index + 1).ToString & ". " & ListBox1.Items(e.Index).ToString
e.Graphics.DrawString(itemText, myFont, myBrush, e.Bounds)
End If
End Sub
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
End Sub
End Class