Fill a rectangle Linear Gradient Brush : Gradient Brush « 2D « C# / CSharp Tutorial






Fill a rectangle Linear Gradient Brush
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class BrushLinearGradient : System.Windows.Forms.Form
{
  public BrushLinearGradient()
  {
    this.BackColor = System.Drawing.Color.White;
    this.ClientSize = new System.Drawing.Size(400, 400);
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.BrushLinearGradient_Paint);
  }

  static void Main() 
  {
    Application.Run(new BrushLinearGradient());
  }

  private void BrushLinearGradient_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
    Graphics g = e.Graphics;

    Brush brGradient = new LinearGradientBrush(new Rectangle(0, 0, 200, 200), Color.Black, Color.LightGray, 45, false);
    g.FillRectangle(brGradient, 10, 10, 200, 200);
  }
}








27.27.Gradient Brush
27.27.1.Linear Gradient BrushLinear Gradient Brush
27.27.2.Fill a rectangle Linear Gradient BrushFill a rectangle Linear Gradient Brush
27.27.3.PathGradient.CenterPoint