如何颜色名称转换为相应的十六进制再presentation? [英] How to convert color name to the corresponding hexadecimal representation?

查看:203
本文介绍了如何颜色名称转换为相应的十六进制再presentation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

blue 

转换为:

#0000FF

我写的是:

颜色颜色= Color.FromName(蓝色);

但我不知道怎么弄的十六进制再presentation。 任何的方式来解决,这是AP preciated。先谢谢了。

But I don't know how to get the hexadecimal representation. Any way to solve this is appreciated. Thanks in advance.

推荐答案

你成功了一半。使用 .ToArgb 将其转换为它的数字的值,然后将其格式化为十六进制值。

You're half way there. Use .ToArgb to convert it to it's numberical value, then format it as a hex value.

int ColorValue = Color.FromName("blue").ToArgb();
string ColorHex = string.Format("{0:x6}", ColorValue);

这篇关于如何颜色名称转换为相应的十六进制再presentation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆