illustrates filling shapes with a brush

image_pdfimage_print


   

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Example21_4 : System.Windows.Forms.Form
{
  private System.ComponentModel.Container components = null;

  public Example21_4()
  {
    InitializeComponent();
  }

  private void InitializeComponent()
  {
    this.BackColor = System.Drawing.Color.White;
    this.ClientSize = new System.Drawing.Size(400, 400);
    this.Name = "Example21_4";
    this.Text = "Example21_4";
    this.Paint += new System.Windows.Forms.
      PaintEventHandler(this.Example21_4_Paint);
  }


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

  private void Example21_4_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
    Graphics g = e.Graphics;
    Brush brSolid = new SolidBrush(Color.Blue);
    Brush brHatch = new HatchBrush(HatchStyle.HorizontalBrick,
      Color.Red, Color.Yellow);
    Brush brGradient = new LinearGradientBrush(new Rectangle(0, 0, 200, 200), Color.Black, Color.LightGray, 45, false);
    g.FillRectangle(brGradient, 10, 10, 200, 200);
    g.FillEllipse(brHatch, 200, 200, 150, 190);
    g.FillPie(brSolid, 0, 0, 300, 300, 285, 75);
  }
}


           
          


This entry was posted in 2D Graphics. Bookmark the permalink.