颜色下拉COMBOBOX控件(vb.net)
来源:互联网 发布:伊丽莎白雅顿 知乎 编辑:程序博客网 时间:2024/04/30 12:10
前不久,有位朋友发帖,寻求颜色选择的COMBOBOX 的制作方法,经过试验,整理了出来,仅供参考。
(注:如有引用,请注明出处和作者) --闵峰(东莞)
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()
End Sub
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
Dim colorname As String = ComboBox1.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.ComboBox1.Font, b2, rect.X, rect.Y)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filllistboxwithcolors()
End Sub
(注:如有引用,请注明出处和作者) --闵峰(东莞)
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()
End Sub
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
Dim colorname As String = ComboBox1.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.ComboBox1.Font, b2, rect.X, rect.Y)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
filllistboxwithcolors()
End Sub
- 颜色下拉COMBOBOX控件(vb.net)
- 颜色下拉COMBOBOX控件(vb.net)
- VB.net中COMBOBOX控件下拉颜色的变化
- VB.NET控件之ComboBox
- 用ComboBox控件实现颜色下拉框
- [VB.NET]请问有什么办法把一个自定义控件添加到comboBox的下拉框中去呢?
- [VB.NET]comboBox控件下拉栏里添加多条数据
- 承载 ComboBox 控件的 DataGridColumnStyle (VB.NET)
- [VB.NET]VB.net中如何直接把Combobox下拉项拖放到另一个Combobox
- VB.Net自己写的一个控件:ComboBox下拉列表中显示多列数据(可以绑定数据表)
- 利用ComboBox和SymbologyControl控件实现下拉式颜色带
- 下拉列表:comboBox控件
- ComboBox自定义下拉控件
- vb.net入门——ComboBox 控件的使用
- combobox 添加颜色下拉框
- ArcEngine+C# ——下拉框(ComboBox)颜色控件 (转)
- ArcEngine+C# ——下拉框(ComboBox)颜色控件 (转)
- [VB.NET]如何把Combobox的下拉列表显示成Checkbox?
- 我们都是T-BAG
- 十大网页设计者必看的网站
- VB.NET状态栏控件上添加任意控件
- socket编程各数据类型
- CString 操作指南
- 颜色下拉COMBOBOX控件(vb.net)
- ASP.NET2.0雷霆之怒盗链者的祝福【月儿原创】
- 技巧 vb.net中的操作符应用实例
- 将窗口移动到前端, BringWindowToTop() 的问题
- Jsp单选按钮的实现
- 在VB.NET中怎么实现多窗体同步
- Java的字符串操作
- Visual Basic.Net中的文件操作
- 关于提高自己JAVA水平的十大技术