如何制作新颜色? [英] How can I make a new color?
问题描述
我在C#中有一个表单,想要在3个 TextBox
控件中输入为红色,绿色和蓝色,并设置新的颜色。例如:当我单击 MAKE COLOR按钮时,红色= 3,绿色= 2,蓝色= 5
,标签将为我显示新颜色。
I have a form in C# that I want to enter as red, green and blue in 3 TextBox
controls and make a new color. For example: red=3, green=2, blue=5
when I click on "MAKE COLOR" button, a label shows me the new color.
推荐答案
让我们假设您有一些类似于以下的代码:
Let us assume that you have some code that looks similar to this:
int red = Convert.ToInt32(RedColorComponentValueTextBox.Text);
int green = Convert.ToInt32(GreenColorComponentValueTextBox.Text);
int blue = Convert.ToInt32(BlueColorComponentValueTextBox.Text);
//Don't forget to try/catch this
然后从中创建颜色这些值,请尝试
Then to create the color from these values, try
Color c = Color.FromArgb(red, green, blue);
然后设置 ForeColor
属性(或标签的 BackColor
属性-不知道要更改哪一个),将标签更改为 c
。
Then set the ForeColor
property (or the BackColor
property -- not sure which one you meant to change) of the label to c
.
您需要使用System.Drawing
You will need to have
using System.Drawing;
在您的代码文件(或类)序言中。
in your code file (or class) preamble.
注意:如果您还希望具有alpha分量,则可以尝试以下操作:
Note: If you wanted to also have an alpha component, you could try this:
Color c = Color.FromArgb(alpha, red, green, blue);
一般提示:如果要使用<$ c $格式的HTML / CSS颜色规范c> #RRGGBB 例如#335577
,尝试以下模式
General hint: If you want to use an HTML/CSS color specification of the form #RRGGBB
e.g. #335577
, try this pattern
int red = 0x33, green = 0x55, blue = 0x77;
这篇关于如何制作新颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!