C# 如何将十六进制 #FFFFFF 转换为 System.Drawing.Color
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12155811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert Hexadecimal #FFFFFF to System.Drawing.Color
提问by user1531040
Possible Duplicate:
How to get Color from Hex color code using .NET?
I want to convert a string like #FFFFFFto System.Drawing.Color. How do you do that?
我想将字符串转换#FFFFFF为System.Drawing.Color. 你是怎样做的?
采纳答案by varg
string hex = "#FFFFFF";
Color _color = System.Drawing.ColorTranslator.FromHtml(hex);
Note: the hash is important!
注意:哈希很重要!
回答by codeteq
Remove the '#' and do
删除“#”并执行
Color c = Color.FromArgb(int.Parse("#FFFFFF".Replace("#",""),
System.Globalization.NumberStyles.AllowHexSpecifier));
回答by SidAhmed
You can do
你可以做
var color = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
Or this (you will need the System.Windows.Medianamespace)
或者这个(你需要System.Windows.Media命名空间)
var color = (Color)ColorConverter.ConvertFromString("#FFFFFF");

