[英]Method to create any background in C#
I'm trying to create a method in C#, that uses colors. 我正在尝试在C#中创建一个使用颜色的方法。
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".
这是错误消息: "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);
我想这样称呼它: Layoutgenerator(WhiteSmoke, LightGray);
ColorA
and ColorB
are already colors, so ColorA
和ColorB
已经是颜色,所以
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.