Hi Samuel,
As the document said,
Return Value
An element of the KnownColor enumeration, if the Color structure is created
from a pre-defined color by using either the FromName method or the
FromKnownColor method; otherwise, zero.
Remarks
A pre-defined color is also called a known color and is represented by an
element of the KnownColor enumeration. When the ToKnownColor method is
applied to a Color structure that is created by using the FromArgb method,
the ToKnownColor method returns zero, even if the ARGB value matches the
ARGB value of a pre-defined color. The ToKnownColor method also returns
zero when it is applied to a Color structure that is created by using the
FromName method with an invalid string name.
[link]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDrawingColorClassToKnownColorTopic.asp
So I think we can compare the argb value with the knowncolors' to know
which knowncolor matched current color.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim kc As Color = Color.FromKnownColor(KnownColor.Blue)
Dim cr As Color = Color.FromArgb(kc.ToArgb())
Dim c As KnownColor
For i As Integer = 1 To 137
If Color.FromKnownColor(i).ToArgb() = cr.ToArgb() Then
Debug.WriteLine(CType(i, KnownColor).ToString())
End If
Next
End Sub
So you will use the method very frequently, we can build a hashtable with
argb to knowncolor name mapping, so that the performance will be better.
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.