| 网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 |
![]() |
| Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道 |
前不久,有位朋友发帖,寻求颜色选择的COMBOBOX 的制作方法,经过试验,整理了出来,仅供参考。 网管联盟bitsCN@com
(注:如有引用,请注明出处和作者)
中国网管联盟bitsCN.com
--闵峰(东莞)
网管网www_bitscn_com
Private Sub filllistboxwithcolors()
Me.ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
Me.ComboBox1.ItemHeight = 15
@#避免闪烁beginupdate
Me.ComboBox1.BeginUpdate()
ComboBox1.Items.Clear()
Dim pi As Reflection.PropertyInfo
For Each pi In GetType(Color).GetProperties(Reflection.BindingFlags.Public Or Reflection.BindingFlags.Static)
Me.ComboBox1.Items.Add(pi.Name)
Next
ComboBox1.EndUpdate()
网管下载dl.bitscn.com
End Sub 网管bitscn_com
Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
If e.Index < 0 Then Exit Sub
Dim rect As Rectangle = e.Bounds @#每一项的边框
@#绘制项如果被选中则显示高亮显示背景,否则用白色
If e.State And DrawItemState.Selected Then
e.Graphics.FillRectangle(SystemBrushes.Highlight, rect)
Else
e.Graphics.FillRectangle(SystemBrushes.Window, rect)
End If 网管联盟bitsCN_com
Dim colorname As String = ComboBox1.Items(e.Index)
Dim b As New SolidBrush(Color.FromName(colorname)) 网管网www.bitscn.com
@#缩小选定项区域()
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.ComboBox1.Font, b2, rect.X, rect.Y)
End Sub 网管u家u.bitsCN.com
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filllistboxwithcolors()
End Sub
网管bitscn_com
|
0
|
评论加载中…