C# - 如何将Fore Color更改为自定义RGB值

时间:2017-08-08 12:44:06

标签: c# colors rgb

我创建了一个标签,如果某个事件触发,我需要以编程方式将其颜色更改为特定的RGB颜色代码。

我试过这样:

statusStripTestLabel.ForeColor = new Color(128, 64, 64);

奖金:

Set it to a RGBA color.

但我得到Color does not have a constructor which accepts 3 arguments.

那么我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

statusStripTestLabel.ForeColor = Color.FromArgb(128, 64, 64); //Alpha is implicitly 255.

statusStripTestLabel.ForeColor = Color.FromArgb(255, 128, 64, 64); //Alpha is explicitly 255. You can change the value of the first parameter to specify the alpha you want.

答案 1 :(得分:0)

你在尝试JAVA有点正确。 在c#中,它是,

yourComponent。前景色=颜色。 FromArgb(theARGB_Code);

*注意并非所有组件都支持透明度