且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从solidcolorbrush获取颜色名称

更新时间:2023-01-27 14:39:45

如果你的意思是System.Drawing.SolidBrush类型的对象,它有一个名为
Color 的属性,类型为System.Drawing.Color,你可以用于获取画笔的颜色。

If you mean an object of type System.Drawing.SolidBrush, it has a property named Color of type System.Drawing.Color, which you can use to get the color of the brush.

如果您的问题是将System.Drawing.Color翻译为命名颜色(即字符串,如"红色"), 您可以使用方法
ToKnownColor

If your problem is translating the System.Drawing.Color to a named color (i.e., a string such as "Red"), you can use the method ToKnownColor:

https://msdn.microsoft.com/en-us/library/system.drawing.color.toknowncolor(v = vs.110)的.aspx

ToKnownColor返回一个枚举,您可以在枚举上调用.ToString()将其转换为字符串。

ToKnownColor returns an enum, and you can call .ToString() on the enum to convert it to a string.

请注意,并非所有可能的颜色都可以转换为名称。 ToKnownColor将返回0,而不是KnownColor枚举的成员,y颜色不是从已知名称创建的。

Be aware that not every possible color can be translated to a name. ToKnownColor will return 0, instead of a member of the KnownColor enumeration, y the color was not created from a known name.