using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace LinearGradientBrushes
{
    public partial class frm33LinearGradientBrushes : Form
    {
        public frm33LinearGradientBrushes()
        {
            InitializeComponent();
        }

        private void frm33LinearGradientBrushes_Paint(object sender, PaintEventArgs e)
        {
            // Define a brush with two points and their colors.
            using (LinearGradientBrush brush = new LinearGradientBrush(
                new Point(10, 10), new Point(155, 50), Color.Red, Color.White))
            {
                e.Graphics.FillRectangle(brush, 10, 10, 140, 50);
                e.Graphics.DrawRectangle(Pens.Black, 10, 10, 140, 50);
            }

            // Define a brush with a Rectangle, colors, and gradient mode.
            Rectangle rect = new Rectangle(160, 10, 125, 50);
            using (LinearGradientBrush brush = new LinearGradientBrush(
                rect, Color.Blue, Color.White, LinearGradientMode.ForwardDiagonal))
            {
                e.Graphics.FillRectangle(brush, rect);
                e.Graphics.DrawRectangle(Pens.Black, rect);
            }

            // Define a gradient with more than 2 colors.
            rect = new Rectangle(10, 70, 275, 50);
            using (LinearGradientBrush brush = new LinearGradientBrush(
                rect, Color.Blue, Color.White, 0f))
            {
                // Create a ColorBlend object. Note that you
                // must initialize it before you save it in the
                // brush's InterpolationColors property.
                ColorBlend colorBlend = new ColorBlend();
                colorBlend.Colors = new Color[]
                {
                    Color.Red, Color.Orange, Color.Yellow, Color.Lime,
                    Color.Blue, Color.Indigo, Color.Violet,
                };
                colorBlend.Positions = new float[]
                {
                    0f, 1/6f, 2/6f, 3/6f, 4/6f, 5/6f, 1f
                };
                brush.InterpolationColors = colorBlend;

                e.Graphics.FillRectangle(brush, rect);
                e.Graphics.DrawRectangle(Pens.Black, rect);
            }
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // frm33LinearGradientBrushes
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(294, 134);
            this.Name = "frm33LinearGradientBrushes";
            this.Text = "LinearGradientBrushes";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.frm33LinearGradientBrushes_Paint);
            this.ResumeLayout(false);

        }

        #endregion
    }
}