How about something like this:
public static class ColorExtensions
{
public static Color WithAlpha(this Color color, double opacity)
{
byte op = (byte)(opacity*255);
return Color.FromArgb(op, color.R, color.G, color.B);
}
}
The key is the this
keyword in the first parameter. That (as well as being a static
method in a static
class) indicates to the compiler that this is an extension method.
Color transparentblue = Color.Blue.WithAlpha(0.5);
Further Reading