使用c#将背景颜色设置为Colorcode [英] Setting background color to a Colorcode using c#

查看:442
本文介绍了使用c#将背景颜色设置为Colorcode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
我正在使用wpf和c#

如何使用 c#

推荐答案

参见 http://msdn.microsoft.com/en-us/library/system.windows.controls.control.background(v = vs.110).aspx [ ^ ]。对于数字颜色,使用#rgb形式的字符串,使用每个字符位置的十六进制值0到F或00到FF。因此#F00#FF0000都表示红色。
See http://msdn.microsoft.com/en-us/library/system.windows.controls.control.background(v=vs.110).aspx[^]. For numeric colours use a string in the form of "#rgb", using the hex values 0 through F, or 00 through FF for each character position. Thus "#F00" and "#FF0000" both represent the colour red.


这样就没有一种简单的方法可以用十六进制字符串中的alpha包含颜色。



我认为你的答案取决于你的位置从中获取颜色和alpha值。



单独的RGB颜色可以从HTML十六进制字符串中解析:



颜色= ColorTranslator.FromHtml(#E7EFF2);



如果您有单独的alpha值,则可以应用此(docs):



颜色= ColorTranslator.FromHtml(#E7EFF2);

颜色透明= Color.FromArgb(128,颜色);



或者你可能需要解析字符串并将其拆分以将十六进制对转换为整数值。



PS原谅英文拼写,但颜色肯定应该有'u':)
There isn't an easy way to get the colour with alpha included from a hex string in this way.

I think your answer depends on where you're getting the colour and alpha values from.

The RGB colour alone can be parsed from an HTML hex string:

Color colour = ColorTranslator.FromHtml("#E7EFF2");

If you have a separate alpha value you can then apply this (docs):

Color colour = ColorTranslator.FromHtml("#E7EFF2");
Color transparent = Color.FromArgb(128, colour);

Alternatively you may need to parse the string and split it out to convert the hex pairs into integer values.

PS excuse English spelling, but colour should definitely have a 'u' in it :)


这篇关于使用c#将背景颜色设置为Colorcode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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