Method to create any background in C#

64 Views Asked by At

I'm trying to create a method in C#, that uses colors.

public void Layoutgenerator(Color ColorA, Color ColorB)
    {
        LinearGradientBrush lgb = new LinearGradientBrush();
        lgb.StartPoint = new Point(0, 0);
        lgb.EndPoint = new Point(1, 1);
        lgb.GradientStops.Add(new GradientStop(Colors.ColorA, 0.0));
        lgb.GradientStops.Add(new GradientStop(Colors.ColorB, 1.0));
        this.Background = lgb;
    }

But unfortunately it's not working. This is the error message: "System.Windows.Media.Colors" does not contain a definition for "ColorB".

Does someone know my fallacy?

I want to call it this way: Layoutgenerator(WhiteSmoke, LightGray);

1

There are 1 best solutions below

0
C.Evenhuis On BEST ANSWER

ColorA and ColorB are already colors, so

lgb.GradientStops.Add(new GradientStop(ColorA, 0.0));
lgb.GradientStops.Add(new GradientStop(ColorB, 1.0));

should do the trick. You'll have to call the method using:

Layoutgenerator(Colors.WhiteSmoke, Colors.LightGray);