Kita bisa mengubah ukuran huruf, jenis huruf ataupun warna dari item yang di pilih.Mungkin ada diantara kalian yang bosan dengan warna dari listbox.
Bagi Temen-temen yang tertarik silahkan di coba saja.
- Untuk langkah pertama ubah property DrawMode ListBox Menjadi OwnerDrawFixed . caranya bisa dengan menuliskan script berikut pada Form_Load
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
- Lalu setelah itu tuliskan script di bawah ini pada ListBox1_DrawItem
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground()
Dim myBrush As Brush = Brushes.White
Dim itemColor As Brush = Brushes.Black
Dim myPen As Pen = Pens.Yellow
If e.State And DrawItemState.Selected = DrawItemState.Selected Then
myBrush = Brushes.Black
myPen = Pens.Red
End If
Select Case e.Index
Case 0
itemColor = Brushes.DarkOrange
Case 1
itemColor = Brushes.Green
Case 2
itemColor = Brushes.Black
Case 3
itemColor = Brushes.Chocolate
Case 4
itemColor = Brushes.Gold
Case 5
itemColor = Brushes.Cyan
End Select
e.Graphics.FillRectangle(myBrush, e.Bounds)
e.Graphics.DrawRectangle(myPen, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), e.Font, itemColor, e.Bounds)
End Sub
e.DrawBackground()
Dim myBrush As Brush = Brushes.White
Dim itemColor As Brush = Brushes.Black
Dim myPen As Pen = Pens.Yellow
If e.State And DrawItemState.Selected = DrawItemState.Selected Then
myBrush = Brushes.Black
myPen = Pens.Red
End If
Select Case e.Index
Case 0
itemColor = Brushes.DarkOrange
Case 1
itemColor = Brushes.Green
Case 2
itemColor = Brushes.Black
Case 3
itemColor = Brushes.Chocolate
Case 4
itemColor = Brushes.Gold
Case 5
itemColor = Brushes.Cyan
End Select
e.Graphics.FillRectangle(myBrush, e.Bounds)
e.Graphics.DrawRectangle(myPen, e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), e.Font, itemColor, e.Bounds)
End Sub
0 komentar:
Posting Komentar