Home

GDI+: Introduction to Brushes

 

The Brush

 

Introduction

Line-based and closed shapes require a pen to show their shape. The particularity with closed shapes is that they can be filled, with a color, a picture, or a pattern.

A brush is an object that holds a color, a picture, or a drawing pattern and that is used to fill the interior of a closed shape. This definition also means that there are various types of brushes with different goals. To meet these goals, the .NET Framework provides support for brushes in various namespaces with different classes. The parent of all brushes is the Brush class defined in the System::Drawing namespace.

Using a Brush

Because the main job of a brush is to fill a closed shape, the Graphics class provides a method that corresponds to each of the closed shapes we reviewed to draw in the previous lesson in order to fill it. The methods are:

  • FillRectangle: Used to fill the interior of a rectangle or a square
  • FillRectangle: Used to fill the interior of a series of rectangles
  • FillEllipse: Used to fill the interior of an ellipse or a circle
  • FillPolygon: Used to fill the interior of a polygon
  • FillPie: Used to fill the interior of a pie
  • FillPath: Used to fill the interior of a graphic path

To fill out a shape, call one of these methods, pass it a brush value, followed by the location and dimensions of the shape. For example, if you want to draw a rectangle and fill it with a brush, you would use code similar to:

private: System::Void Form1_Paint(System::Object *  sender,PaintEventArgs *  e)
{
	e->Graphics->FillRectangle(SomeBrush, 20, 20, 200, 160);
}

Over all, there are four types of brushes.

 

Home Copyright © 2004-2010 FunctionX, Inc.