Brush

Why Trust Techopedia

What Does Brush Mean?

Brush is an abstract base class used in C# programming language to define objects for filling the interiors of graphical shapes with a solid color, gradient pattern, image or drawing.

Advertisements

Brush class cannot be instantiated itself but forms the base for all its derived classes, which describe how the graphical area is painted. The graphical shapes that can be filled using brushes include rectangles, ellipses, pies, polygons and paths. Brush objects can be used with graphical objects to create solid shapes and to render text.

Techopedia Explains Brush

In .NET framework 4.0, brush class is implemented in two forms: the brush used in the Graphics Device Interface+ (GDI+) and the Windows Presentation Framework (WPF) brush. In the former case, brush class inherits from System.Drawing and uses the concept of current brush; the latter inherits from System.Windows.Media and the brush object must be passed for each drawing call. The WPF brush has advanced features that enable users to paint user interface objects with anything from simple solid colors to complex sets of patterns and images.

Brush class has the following features:

  • While inheriting from brush class, clone method has to be overridden.
  • All the derived classes representing the brush objects cannot be inherited.
  • Because the brush object consumes system resources, a dispose method needs to be called at the end of its usage.

Brush class is one of the drawing resource classes used to provide different filling pattern for an enclosed surface. It forms a managed wrapper to the underlying unmanaged native Win32 GDI resource, HBRUSH. As one of the fundamental components of GDI+, which is designed for performance and ease of use, it is used in combination with other GDI+ objects, such as pens and colors, to render graphical images on Windows forms and controls.

The different types of brushes used in GDI+ are implemented in the following classes:

  • SolidBrush: Used to define a single-color brush that can be used to fill graphical shapes.
  • TextureBrush: Holds an image as its member and uses that image to fill the interior of a closed shape. A picture file with a normal graphics file extension (like .bmp) is passed as an input during its creation.
  • LinearGradientBrush: Encapsulates both two-color gradients and custom multicolor gradients. It is used to fill a shape with gradually changing color. For example, a two-color gradient brush can be used to fill a rectangle whose left edge is black and gradually changes to red on its right edge. It is similar to solid brush as it is color-based, but differs in that it has two colors applied on two sides, merging to create a transition, or fading effect. The two types of gradient brushes are linear and path. Linear gradient brushes start with one color and blend to another color in a horizontal or vertical direction, or parallel to a slanted line. It is used in closed shapes. Path gradient is applied on a path created by connecting a series of points to get a closed shape, the interior of which can be filled as a gradient. Path gradients can be customized to produce different effects
Advertisements

Related Terms

Margaret Rouse
Technology expert
Margaret Rouse
Technology expert

Margaret is an award-winning writer and educator known for her ability to explain complex technical topics to a non-technical business audience. Over the past twenty years, her IT definitions have been published by Que in an encyclopedia of technology terms and cited in articles in the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine, and Discovery Magazine. She joined Techopedia in 2011. Margaret’s idea of ​​a fun day is to help IT and business professionals to learn to speak each other’s highly specialized languages.