Creates a rainbow brush. - CSharp System.Windows.Media

CSharp examples for System.Windows.Media:Brush

Description

Creates a rainbow brush.

Demo Code


using System.Windows.Media;
using System.Windows;
using System.Linq;
using System.Collections.Generic;

public class Main{
        /// <summary>
        /// Creates a rainbow brush.
        /// </summary>
        /// <returns>
        /// A rainbow brush.
        /// </returns>
        public static LinearGradientBrush CreateRainbowBrush(bool horizontal = true)
        {//from w w  w. j  av  a  2s  . c o m
            var brush = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = horizontal ? new Point(1, 0) : new Point(0, 1) };
            brush.GradientStops.Add(new GradientStop(Colors.Red, 0.00));
            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.50));
            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.00));
            return brush;
        }
}

Related Tutorials