Set System.Drawing.Color values

后端 未结 6 1875
耶瑟儿~
耶瑟儿~ 2021-02-04 23:13

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 o

6条回答
  •  北海茫月
    2021-02-04 23:32

    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);
    

提交回复
热议问题