本文整理汇总了VB.NET中System.Windows.Forms.DrawMode枚举的典型用法代码示例。如果您正苦于以下问题:VB.NET DrawMode枚举的具体用法?VB.NET DrawMode怎么用?VB.NET DrawMode使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了DrawMode枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: InitializeListBox
Private WithEvents ListBox1 As New ListBox()
Private Sub InitializeListBox()
ListBox1.Items.AddRange(New Object() _
{"Red Item", "Orange Item", "Purple Item"})
ListBox1.Location = New System.Drawing.Point(81, 69)
ListBox1.Size = New System.Drawing.Size(120, 95)
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
Controls.Add(ListBox1)
End Sub
Private Sub ListBox1_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles ListBox1.DrawItem
' Draw the background of the ListBox control for each item.
e.DrawBackground()
' Define the default color of the brush as black.
Dim myBrush As Brush = Brushes.Black
' Determine the color of the brush to draw each item based on
' the index of the item to draw.
Select Case e.Index
Case 0
myBrush = Brushes.Red
Case 1
myBrush = Brushes.Orange
Case 2
myBrush = Brushes.Purple
End Select
' Draw the current item text based on the current
' Font and the custom brush settings.
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), _
e.Font, myBrush, e.Bounds, StringFormat.GenericDefault)
' If the ListBox has focus, draw a focus rectangle around _
' the selected item.
e.DrawFocusRectangle()
End Sub