당신이 VS와 같은 기능을 원하고 Named Colors와 다른 방식으로 시스템 색상을 나타내기를 원할 때까지 이것들 중 하나는 귀중한 것입니다. 예 배경으로 색상을 사용하여 :
' 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에, 다음, OwnerDrawFixed
에 DrawMode을 설정
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 항목 rect.
표준 창 텍스트 색상이 모두 표시되지 않습니다. "밝은"테마의 경우, 보라색과 검정색 등은 색 이름을 숨기거나 읽을 수 없게합니다. 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
그런 다음 콤보 상자에서 상속 클래스에있는 모든이를 사용하거나 별개의 컨트롤과 같은 UserControlif 당신을 구축 할 수 있습니다. 이러한 경우에 호출되는 DLL에 코드로 남겨 둘 수도 있습니다. 나는 CodeProject에 대해 아마도 12 명의 그런 생물을 언급 할 것이다.
http://social.msdn.microsoft.com/Forums/it-IT/e21c8b6f-6750-46b1-86be-c69ecac9e7a5/colorpicker-combobox?forum=winforms –
안녕하세요, 많은 도움에 감사드립니다. 한스, 링크에 감사드립니다. 정확히 내가 필요한 것입니다! – user3012629