how to change transparency of a color in c#

前端 未结 4 845
天命终不由人
天命终不由人 2021-02-12 11:38

I am using SSRS reportviewer to generate a report using objects. In my program, I am asking the user to input a string of commonly known colors such as \"Red\", \"<

4条回答
  •  误落风尘
    2021-02-12 11:58

    I created a handy extension method.

    public static class ColorExtensions
    {
        ...
        public static Color WithA(this Color color, int newA) => Color.FromArgb(newA,color);
    }
    

    Usage:

    newitem.ChartColor = "red";
    Color mycolor = Color.FromName(newitem.ChartColor);
    
    Color myColorAlt1 = myColor.WithA(0x56);
    Color myColorAlt2 = myColor.WithA(0x28);
    

    or, if you needed it right away:

    Color mycolor = Color.FromName(newitem.ChartColor).WithA(0x56);
    

提交回复
热议问题