2017-08-08 24 views
0

我創建了一個標籤,並且需要將它的顏色以編程方式更改爲特定的RGB顏色代碼(如果某個事件觸發)。C# - 如何將Fore Color更改爲自定義RGB值

我想它是這樣的:

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

獎金:

Set it to a RGBA color. 

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

那麼,如何解決這個問題?

回答

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. 
+0

在那裏錯過了一個參數。 – marsze

+1

實際上,只需爲A(或Alpha指示不透明度)添加另一個值爲255,以便讀取爲Color.FromArgb(255,128,64,64); – RoguePlanetoid

+0

其實我沒有。 FromArgb()方法有4個重載。如果你想指定alpha,你可以使用接受4個參數的重載。由於該問題沒有指定alpha,所以他可以使用接受上述3個參數(int red,int green,int blue)的重載。 –

0

你正在嘗試的是什麼在JAVA中有點正確。 在c#中,它是,

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

*注意並非所有組件都支持透明度

相關問題