Set System.Drawing.Color values

Sudantha  picture Sudantha · May 16, 2011 · Viewed 200.2k times · Source

Hi how to set R G B values in System.Drawing.Color.G ?

which is like System.Drawing.Color.G=255; is not allowed because its read only

Property or indexer 'System.Drawing.Color.G' cannot be assigned toit is read only

i just need to create a Color Object by assigning custom R G B values

Answer

Darin Dimitrov picture Darin Dimitrov · May 16, 2011

You could create a color using the static FromArgb method:

Color redColor = Color.FromArgb(255, 0, 0);

You can also specify the alpha using the following overload.