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\"
, \"<
You can set with this function
static Color SetTransparency(int A, Color color)
{
return Color.FromArgb(A, color.R, color.G, color.B);
}
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);
There is a method that does exactly what you need Color.FromArgb(int alpha, Color baseColor).
Valid alpha
values are 0 through 255. Where 255 is the most opaque color and 0 a totally transparent color.
Use example
Color newColor = Color.FromArgb(newAlpha, mycolor);
I think what needs to be included among these answers is that the alpha value indicates how transparent the color is with 0 being the most transparent and with 255 being the most opaque. Here is a summary:
A L P H A V A L U E
0 [<--- most transparent] ... ... ... [most opaque --->] 255