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总结
以上是内存溢出为你收集整理的VB.net中COMBOBOX控件下拉颜色的变化全部内容,希望文章能够帮你解决VB.net中COMBOBOX控件下拉颜色的变化所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)