Visual Basic 中学校 > Visual Basic サンプル集 > Visual Basic サンプル集目次 > Windows.Forms.ListBox >
行ごとに背景色を変えてしましまにする
Private Sub
Form1_Load(ByVal sender
As System.Object, ByVal e
As System.EventArgs)
Handles MyBase.Load ListBox1.DrawMode = DrawMode.OwnerDrawFixed End Sub |
Private
Sub ListBox1_DrawItem(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles
ListBox1.DrawItem
If e.Index = -1
Then e.DrawBackground()
'奇数項目の背景をスカイブルーにする。 Dim myBrush As Brush = New SolidBrush(ListBox1.ForeColor) e.Graphics.DrawString(ListBox1.Items(e.Index), e.Font, myBrush, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)) e.DrawFocusRectangle() End Sub |
メモ:このサンプルではEnabled = Falseの場合、およびSelectionMode = Noneの場合の配慮がされていません。