动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 带颜色的listbox控件

作者:郁郁小蝎 来源:中国站长学院 
阅读 1609 人次 , 2006-2-15 14:30:00 

 Private Sub filllistboxwithcolors()

        Me.ListBox1.DrawMode = DrawMode.OwnerDrawFixed

        Me.ListBox1.ItemHeight = 24

        '避免闪烁

        Me.ListBox1.BeginUpdate()

        ListBox1.Items.Clear()

        Dim pi As Reflection.PropertyInfo

        For Each pi In GetType(Color).GetProperties(Reflection.BindingFlags.Public Or Reflection.BindingFlags.Static)

            Me.ListBox1.Items.Add(pi.Name)

        Next

        ListBox1.EndUpdate()

 

    End Sub

 

    Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem

        Dim rect As Rectangle = e.Bounds '每一项的边框

        If e.State And DrawItemState.Selected Then

            e.Graphics.FillRectangle(SystemBrushes.Window, rect)

 

        End If

        Dim colorname As String = ListBox1.Items(e.Index)

        Dim b As New SolidBrush(Color.FromName(colorname))

        rect.Inflate(-16, -2)

        e.Graphics.FillRectangle(b, rect)

        e.Graphics.DrawRectangle(Pens.Black, rect)

        Dim b2 As Brush

        If CInt(b.Color.R) + CInt(b.Color.G) + CInt(b.Color.B) > 128 * 3 Then

            b2 = Brushes.Black

        Else

            b2 = Brushes.White

 

        End If

        e.Graphics.DrawString(colorname, Me.ListBox1.Font, b2, rect.X, rect.Y)

    End Sub

  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:按钮列的应用
· 下一篇:可拖动的无标题栏窗体
· 如何搞定DataGrid 分栏的大小
· ASP.NET可交互式位图窗体设计(9)
· CNET JSP BASIC: 安装JSP
· 由C#风潮想起的-给初学编程者的忠告
· DBEngine的类片段(使用自动填充)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077