·您的位置: 首页 » 资源教程 » 编程开发 » ASP.NET » 带颜色的listbox控件

带颜色的listbox控件

类别: ASP.NET教程  评论数:0 总得分:0
 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

-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1