源码如下:
添加brush.GradientOrigin = new Point(.25, .25)及
添加brush.GradientOrigin = new Point(.75, .75)的代码我不小心删了
这里是书中的代码,需要的自己添加就行了
//-------------------------------------------------
// CircleTheRainbow.cs (c) 2006 by Charles Petzold
//-------------------------------------------------
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace Petzold.CircleTheRainbow
{
public class CircleTheRainbow : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new CircleTheRainbow());
}
public CircleTheRainbow()
{
Title = "Circle the Rainbow";
RadialGradientBrush brush = new RadialGradientBrush();
Background = brush;
// Rainbow mnemonic is the name Roy G. Biv.
brush.GradientStops.Add(new GradientStop(Colors.Red, 0));
brush.GradientStops.Add(new GradientStop(Colors.Orange, .17));
brush.GradientStops.Add(new GradientStop(Colors.Yellow, .33));
brush.GradientStops.Add(new GradientStop(Colors.Green, .5));
brush.GradientStops.Add(new GradientStop(Colors.Blue, .67));
brush.GradientStops.Add(new GradientStop(Colors.Indigo, .84));
brush.GradientStops.Add(new GradientStop(Colors.Violet, 1));
}
}
}