I cannot find any correct solution for this
string colorName = ...converting... Brushes.Brown;
So colorName should have 'Brown'
Is it possible?
I cannot find any correct solution for this
string colorName = ...converting... Brushes.Brown;
So colorName should have 'Brown'
Is it possible?
It seems I found a way to do it.
public string GetColorName(Brush brush)
{
string name = "Unknown";
Color c = new Pen(brush).Color;
foreach (KnownColor kc in Enum.GetValues(typeof(KnownColor)))
{
Color known = Color.FromKnownColor(kc);
if (c.ToArgb() == known.ToArgb())
{
name = known.Name;
break;
}
}
return name;
}
To get the desired result, you can use:
string colorName = nameof(Brushes.Brown);
Now colorName
should have the value 'Brown'
.