Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set System.Drawing.Color values

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

like image 939
Sudantha Avatar asked May 16 '11 11:05

Sudantha


People also ask

How to Set System drawing color c#?

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.

How to use color FromArgb in c#?

FromArgb(Int32, Int32, Int32) Creates a Color structure from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

What is drawing color?

Technically, drawing in colored pencil is simply layering semitransparent colors on paper to create vivid paintings. Every color has three qualities: temperature, intensity and value.

How do you get black RGB?

Black = [ 0, 0, 0 ]


2 Answers

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.

like image 142
Darin Dimitrov Avatar answered Oct 01 '22 18:10

Darin Dimitrov


The Color structure is immutable (as all structures should really be), meaning that the values of its properties cannot be changed once that particular instance has been created.

Instead, you need to create a new instance of the structure with the property values that you want. Since you want to create a color using its component RGB values, you need to use the FromArgb method:

Color myColor = Color.FromArgb(100, 150, 75); 
like image 23
Cody Gray Avatar answered Oct 01 '22 20:10

Cody Gray