有没有人知道显示标准颜色名称的Visual Studio(Visual Basic)的color-picker
?显示颜色名称的颜色拾取器
例如,在Visual Studio中,您可以使用具有"Custom"
,"Web"
和"System"
标签的color-picker
来更改控件的颜色。 Web
& System
选项显示颜色名称的列表,而Custom
提供(主要)RGB(这是VB ColorPicker控件的作用)。
谢谢!
有没有人知道显示标准颜色名称的Visual Studio(Visual Basic)的color-picker
?显示颜色名称的颜色拾取器
例如,在Visual Studio中,您可以使用具有"Custom"
,"Web"
和"System"
标签的color-picker
来更改控件的颜色。 Web
& System
选项显示颜色名称的列表,而Custom
提供(主要)RGB(这是VB ColorPicker控件的作用)。
谢谢!
对于其中之一,除非你想像VS一样做,并且将系统颜色与命名的颜色区分开来,使它成为一个弹出窗口或其他窗口,否则它们之间几乎没有任何关系。使用颜色作为背景例如:
' capture the names
Private _Colors As String()
' get the names
' add qualifiers to skip SystemCOlors or
' Transparent as needed
Function GetColorNames As String()
For Each colorName As String In KnownColor.GetNames(GetType(KnownColor))
_Colors.Add(colorName)
End If
Next
' post the names to a CBO:
cboBackColor.Items.AddRange(_Colors)
在形式CBO的DrawMode设置为OwnerDrawFixed
,则:
Private Sub cboSheetBackColor_DrawItem(ByVal sender As Object,
ByVal e As System.Windows.Forms.DrawItemEventArgs)
Handles cboSheetBackColor.DrawItem
Dim Bclr As Color, Fclr As Color
' get the colors to use for this item for this
Bclr = Color.FromName(_Colors(e.Index).ToString)
Fclr = GetContrastingColor(Bclr) ' see below
With e.Graphics
Using br As New SolidBrush(Bclr)
.FillRectangle(br, e.Bounds)
End Using
Using br As New SolidBrush(Fclr)
.DrawString(cboSheetBackColor.Items(e.Index).ToString,
cboSheetBackColor.Font, br,
e.Bounds.X, e.Bounds.Y)
End Using
End With
e.DrawFocusRectangle()
End Sub
您可以只画如Windows/VS中的样本并通过定义矩形填充。通常情况下,这会膨胀,但是如果您正在定义背景颜色,那么它有助于展示它如何看起来具有文本以及比小小的色板更多的颜色 - 因此是填充的CBO项目矩形。
标准窗口文字颜色不会显示在所有的文字上。对于“轻”主题,紫罗兰和黑色等将隐藏/使颜色名称不可读。 GetContrastingColor
是评估当前颜色的亮度的功能,然后返回白色或黑色:
Public Function GetContrastingColor(ByVal clrBase As Color) As Color
' Y is the "brightness"
Dim Y As Double = (0.299 * clrBase.R) _
+ (0.587 * clrBase.G) _
+ (0.114 * clrBase.B)
If (Y < 140) Then
Return Color.White
Else
Return Color.Black
End If
End Function
然后就可以使用这一切,从ComboBox中继承的类,或建立一个UserControlif你喜欢不同的控制。您也可以将它作为代码保存在这些场合调用的DLL中。我应该提到CodeProject上也许有十几个这样的生物。
我不知道现有的控件,但可以使用KnownColor
枚举类和SystemColors
类来获取这些Color
值的所有名称。然后您可以构建自己的控件,例如自定义ComboBox
,与该数据。
http://social.msdn.microsoft.com/Forums/it-IT/e21c8b6f-6750-46b1-86be-c69ecac9e7a5/colorpicker-combobox?forum=winforms –
嗨,非常感谢您的输入,最有帮助。汉斯,感谢您的链接 - 正是我需要的! – user3012629