Set System.Drawing.Color values

后端 未结 6 1877
耶瑟儿~
耶瑟儿~ 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:37

    You can make extension to just change one color component

    static class ColorExtension
    {
        public static Color ChangeG(Color this color,byte g) 
        {
            return Color.FromArgb(color.A,color.R,g,color.B);
        }
    }
    

    then you can use this:

      yourColor = yourColor.ChangeG(100);
    

提交回复
热议问题