Color.ToKnownColor Method

Definition

Gets the KnownColor value of this Color structure.

C#
public System.Drawing.KnownColor ToKnownColor();

Returns

An element of the KnownColor enumeration, if the Color is created from a predefined color by using either the FromName(String) method or the FromKnownColor(KnownColor) method; otherwise, 0.

Remarks

A predefined 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, ToKnownColor returns 0, even if the ARGB value matches the ARGB value of a predefined color. ToKnownColor also returns 0 when it is applied to a Color structure that is created by using the FromName method with a string name that is not valid.

Applies to

Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.1