简单的彩虹笔刷范例,用WPF还真好玩
LinearGradientBrush就可以做线性的渐层
RadialGradientBrush可以做椭圆的渐层
只要将画刷设定到Background属性,就可以在Window填满下列效果了
namespace Cloud.GradiateTheBrush
{
public class GradiateTheBrush : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new GradiateTheBrush());
}
public GradiateTheBrush()
{
this.Title = "Gradiate Brush";
//LinearGradientBrush brush = new LinearGradientBrush();
//brush.StartPoint = new Point(0, 0);
//brush.EndPoint = new Point(1, 0);
RadialGradientBrush brush = new RadialGradientBrush();
this.Background = brush;
brush.GradientStops.Add(new GradientStop(Colors.Red, 0));
brush.GradientStops.Add(new GradientStop(Colors.Orange, 0.17));
brush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.33));
brush.GradientStops.Add(new GradientStop(Colors.Green, 0.5));
brush.GradientStops.Add(new GradientStop(Colors.Blue, 0.67));
brush.GradientStops.Add(new GradientStop(Colors.Indigo, 0.84));
brush.GradientStops.Add(new GradientStop(Colors.Violet, 1));
}
}
}