您的位置:首页 > 其它

[WPF] 彩虹画刷小范例

2010-09-07 15:43 483 查看
简单的彩虹笔刷范例,用WPF还真好玩

LinearGradientBrush就可以做线性的渐层

RadialGradientBrush可以做椭圆的渐层

只要将画刷设定到Background属性,就可以在Window填满下列效果了









using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Reflection;

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));
        }

    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: