Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get color Name from color class [duplicate]

Tags:

c#

I have color coming in the below way

{ Name=ffff8c00, ARGB=(255, 255, 140, 0) }

can i chekc the color name? Whether it is red or green..i wanted the name of color..

Is it possible to find ?

like image 893
Pankaj Avatar asked Dec 04 '25 10:12

Pankaj


1 Answers

You can get the name from KnownColor. Try like below

        string name = "Unknown";
        foreach (KnownColor kc in Enum.GetValues(typeof(KnownColor)))
        {
            Color known = Color.FromKnownColor(kc);
            if (Color.FromArgb(255,255,140,0).ToArgb() == known.ToArgb())
            {
                label1.Text = known.Name;
                break;
            }
        }

Here I just hard code your value and return the name in label named 'label1'.

Check this thread http://social.msdn.microsoft.com/Forums/vstudio/en-US/3c80583e-d0a9-45e9-842a-bd7258f1fd2f/get-color-name-in-c?forum=csharpgeneral

like image 198
Akhil Avatar answered Dec 05 '25 23:12

Akhil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!