按颜色代码(Hex)获取颜色名称 [英] Get Color Name by Color Code(Hex)

查看:951
本文介绍了按颜色代码(Hex)获取颜色名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



如何通过名称获取C#中控件的当前背景颜色?

我们怎样才能通过其HexCode时,通过其名称获取C#中控件的当前背景颜色?



任何帮助将不胜感激



在此先感谢



Muhammed abdussalam

Hello All,

How can we get the current background color of a control in C# by its Name?
How can we get the current background color of a control in C# by its Name when passing its HexCode?

Any help will be appreciated

Thanks in Advance

Muhammed abdussalam

推荐答案

Color colorRed = Color.FromArgb(0xFFFF0000);//A color created with this method will return 0 in ToKnownColor()
//if you get a color from Color.FromKnownColor() or if you choose from color list in designer then it will return the name. Example:
colorRed = form.BackColor;
String name = colorRed.ToKnownColor().ToString();


I不要这总是可能的。由于所有HexCode都不需要命名颜色。



但是你可以获得与HexCodes相对应的颜色对象。



颜色=(颜色)ColorConverter.ConvertFromString(#hexValue);



你也可以使用颜色翻译器

http://msdn.microsoft.com/en-us/library/system.drawing .colortranslator.aspx [ ^ ]



颜色.FromArgb [ ^ ]
I do not this is is always possible. Since all the HexCodes need not have a named color.

However you can get the color object corresponding to the HexCodes.

Color color = (Color)ColorConverter.ConvertFromString("#hexValue");

also you can use color translator
http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator.aspx[^]
or
Color.FromArgb[^]


获取背景颜色我们可以控制的控件名称:

to get the background color Name of the control we can :
Color color;
 color = controlId.BackColor; 
 string colorName = color.Name;


这篇关于按颜色代码(Hex)获取颜色名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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