C# 如何将string 转换为 Color 类型

低调的感觉 2008-11-19 07:40:44
我将 Color 类型的数据转换为 string 类型的数据保存在一个ini文件里
现在读取出来 又想转换为 Color 类型
不知道怎么搞..请高手指教下
最好能附代码..3Q
...全文
604 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
bloodish 2008-11-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 sl2161 的回复:]
引用 6 楼 bloodish 的回复:
引用 1 楼 hulihui 的回复:
Color cl = Color.FromName("Red");


正解


你题目都没看懂,还正解
Color定义的颜色枚举是有限的
[/Quote]
需要存你所说的RGB值吗?既然楼主说了string存出去,就是存Name,FromName就是正解
再说要存,也不是RGB分开存,只要存一个int足以
Color c;
int i = c.ToArgb();
Color.FromArgb(i);
Fibona 2008-11-19
  • 打赏
  • 举报
回复
Color cl = Color.FromName("Red");
sl2161 2008-11-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 bloodish 的回复:]
引用 1 楼 hulihui 的回复:
Color cl = Color.FromName("Red");


正解
[/Quote]

你题目都没看懂,还正解
Color定义的颜色枚举是有限的
bloodish 2008-11-19
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 hulihui 的回复:]
Color cl = Color.FromName("Red");
[/Quote]

正解
wuyq11 2008-11-19
  • 打赏
  • 举报
回复
System.Drawing.ColorTranslator.FromHtml("")
System.Drawing.Color.FromName("");
y63964632 2008-11-19
  • 打赏
  • 举报
回复
关注~
sl2161 2008-11-19
  • 打赏
  • 举报
回复
给个思路:
1.保存Color的RGB值,以分号为分隔符,不要保存为int直接存string
2.利用string的split函数得到保存了RGB的数组
3.通过数组中的值还原成Color

帮你顶一下

长沙三毛 2008-11-19
  • 打赏
  • 举报
回复
Color cl = Color.FromName("Red");

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧