如何以字符串形式存储颜色? [英] How to store Colors in string?
问题描述
如果它们是人类可读格式,我想将Color存储在字符串中,如果不是,则要存储ToArgb().
I want to store Color in string if they are Human Readable format and ToArgb() if they are not.
颜色是红色,然后将其存储在红色"字符串中,如果颜色是绿色的某种变体,则将其存储为"ff40ff80".
Color is Red then store it in "Red" string and If color is say some variant of green then it is store as "ff40ff80".
在运行时,我想将此字符串转换回Color类Object吗?
At runtime I want to convert this strings back to Color class Object?
推荐答案
您很幸运. Color.ToString()
方法将为您做到这一点:
You're in luck. The Color.ToString()
method will do this for you:
返回值
类型:
System.String
如果此颜色是使用 FromName
方法或 FromKnownColor
方法从预定义颜色创建的,则为此Color的名称的字符串;否则为一个包含ARGB组件名称及其值的字符串.
A string that is the name of this Color, if the Color is created from a predefined color by using either the FromName
method or the FromKnownColor
method; otherwise, a string that consists of the ARGB component names and their values.
这篇关于如何以字符串形式存储颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!