是否有人知道color-picker for Visual (Visual )显示标准颜色的名称?
例如,在Visual中,可以使用具有color-picker选项卡的"Custom"、"Web"和"System"来更改控件的颜色。Web & System选项显示颜色名称的列表,而Custom提供(主要是) RGB (这是VB ColorPicker控件所做的)。
谢谢!
发布于 2014-04-25 21:25:15
除了命名的颜色之外,在你想要像VS和呈现系统颜色之外,让它成为弹出的或者其他的颜色之前,这些都是很珍贵的东西。使用颜色作为BackGround的示例:
' 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可以像/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上也可能有十几个这样的生物。
发布于 2014-04-25 20:31:58
我不知道现有的控件,但是您可以使用KnownColor枚举和SystemColors类来获取这些Color值的所有名称。然后,您可以使用该数据构建自己的控件,例如自定义ComboBox。
https://stackoverflow.com/questions/23302414
复制相似问题