| 网站首页 | VB.Net实例分析 | .Net技术文摘 | 下载中心 | VB.Net书籍笔记 | .Net源码 | VBS脚本与组件调用 | Windows2008技术文摘 | 给我们留言 | 
最新公告:

  没有公告

您现在的位置: 乐博网 >> VB.Net实例分析 >> 网络编程 >> 实例分析正文
最新推荐 更多内容
[图文]ListBox现实每行颜色变化-ListBox.DrawItem事件
ListBox现实每行颜色变化-ListBox.DrawItem事件
作者:microsoft    来源:msdn     更新时间:2010-7-6

ListBox现实每行颜色变化-ListBox.DrawItem事件

分类:VB2010

效果图:

 

Public Class Form1

    '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
            Case 3
                myBrush = Brushes.Blue
            Case 4
                myBrush = Brushes.Green
            Case 5
                myBrush = Brushes.MediumAquamarine
            Case 6
                myBrush = Brushes.Black
        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


End Class

  • 上一篇:

  • 下一篇:
  • 【字体: 】【打印此文】【关闭窗口
      相关文章:(只显示最新16条)
    listbox控件事件实例
    VB.Net读取或保存listbox的记录到文件中的实例
    ListBox.OnDrawItem方法的实例

    | 设为首页 | 加入收藏 | 联系站长 | | 友情链接 | 版权申明 |
    乐博网欢迎各种媒体转载我们的原创作品[转载请注明出处];我们鼓励更多VB.Net开发者一起加入研究与探讨;如发现文章访问错误、内容错误或版权疑问、内容有违相关法律(如涉及政治、色情、反动或散布虚假有害信息)等情况,请及时向我们举报,我们将及时纠正!
    联系邮箱:Shiny#vip.qq.com (#替换为@) QQ交流群: 40797788 [闽ICP备05014267号]