Call Winforms ControlPaint.Light() in WPF project Call Winforms ControlPaint.Light() in WPF project wpf wpf

Call Winforms ControlPaint.Light() in WPF project


Try this:

        Brush brush = Brushes.Yellow;        Color color = ((SolidColorBrush) brush).Color;


You could try getting the A,RGB values of the brush, and then pass them to System.Drawing.Color.FromARGB() Pseudo-Code:

Brush br = Brushes.Green;byte a = ((Color)br.GetValue(SolidColorBrush.ColorProperty)).A;byte g = ((Color)br.GetValue(SolidColorBrush.ColorProperty)).G;byte r = ((Color)br.GetValue(SolidColorBrush.ColorProperty)).R;byte b = ((Color)br.GetValue(SolidColorBrush.ColorProperty)).B;System.Windows.Forms.ControlPaint.Light(    System.Drawing.Color.FromArgb((int)a,(int)r,(int)g,(int)b));

I'm not a WPF expert, but the main thing I think you need to keep in mind is the easiest way to do what you are trying is to use System.Drawing.Color.FromArgb() or even System.Drawing.Color.FromName().


You don't need to reference the huge Windows.Forms dll just to lighten a Color. In its simplest terms, you're just multiplying each value by the same factor:

private Color AdjustBrightness(double brightnessFactor){    Color originalColour = Color.Red;    Color adjustedColour = Color.FromArgb(originalColour.A,         (int)(originalColour.R * brightnessFactor),         (int)(originalColour.G * brightnessFactor),         (int)(originalColour.B * brightnessFactor));    return adjustedColour;}

This could of course be improved in several ways (and should), but you get the idea. In fact, this will throw an Exception if a value goes over 255, but I'm sure that you can take care of that. Now you just need to check what type of Brush you need to brighten:

if (brush is SolidColorBrush)     return new SolidColorBrush(AdjustBrightness(((SolidColorBrush)brush).Color));else if (brush is LinearGradientBrush || brush is RadialGradientBrush) {    // Go through each `GradientStop` in the `Brush` and brighten its colour}