If you're new to GDI+, you might want to check out my tutorial GDI+ for Beginners
You can create different types of brushes in GDI+. In this article, I'll show you how to create various types of brushes.
Drawing GDI+ ObjectsThe following code draws a line, an ellipse, a curve, and a polygon object. As you can see from the code, I've used pen object to fill these objects. See more details.
protected
All brush types are defined in System.Drawing and its helper namespaces. Before using brushes, you need to add reference to this namespace. HatchBrush and GradientBrush are defined in System.Drawing.Drawing2D namespace.
You use brushes to fill GDI+ objects with certain kind of brush. You generally call Fill methods of Graphics class to fill various objects such as Ellipse, Arc, or Polygon. There are different kinds of brushes. For example, solid brush, hatch brush, texture brush, and gradient brush.
Solid BrushesSolid brushes are normal brushes with no style. You fill GDI+ object with a color. SolidBrush type is used to work with solid brushes.
Graphics g = e.Graphics; SolidBrush sdBrush1 =
using
The hatch brushes are brushes with a hatch style, a foreground color, and a background color. Hatches are a combination of rectangle lines and the area between the lines. The foreground color defines the color of lines; the background color defines the color of area between lines.
HatchStyle defines the hatch styles.
Member Name
The following code shows how to draw hatch brushes.
Texture BrushesThe texture brushes provides you to use an image as brush and fill GDI+ objects with the brush. The following code use "myfile.bmp" as a brush. You need to define an Image object and create brush with that Image and pass the brush into Fill method of GDI+ objects.
private
This like combines blue and green colors -
LinearGradientBrush lBrush =