
The combo box will list some of the available hatch styles.
UNDERSTANDING SAI BRUSH TEXTURES WINDOWS
Let's create a Windows application that looks like Figure 4.4. HatchStyle returns the hatch brush style of type HatchStyle enumeration, whose members are described in Table 4.1. BackgroundColor returns the color of spaces between the hatch lines, and ForegroundColor represents the color of the hatch lines. HatchBrush has three properties: BackgroundColor, Foreground-Color, and HatchStyle.
UNDERSTANDING SAI BRUSH TEXTURES CODE
For example, the following code line fills an ellipse using hBrush1: We can use this hatch brush to fill graphics objects such as rectangles or ellipses. (HatchStyle.DashedVertical, Color.Blue, Color.Red) The following code creates a hatch brush with a dashed-vertical hatch style, blue background, and red foreground: Public HatchBrush(HatchStyle, Color, Color) Alternatively, an application can refer to the HatchBrush class as. An application needs to provide a reference to 2D before using this class. The HatchBrush class is defined in the 2D namespace. The following code snippet shows the constructor signatures: Second and third Color parameters represent the foreground and background colors. The HatchBrush class constructor takes HatchStyle as its first parameter and Color as the second parameter. The foreground color defines the color of lines the background color defines the color between lines. Hatches are a combination of rectangle lines and the area between the lines. Hatch brushes are brushes with a hatch style, a foreground color, and a background color. The output of Listing 4.3 draws an ellipse, a rectangle, and a pie, as Figure 4.3 shows.įigure 4.3. Listing 4.3 uses red, green, and blue solid brushes and fills an ellipse, a pie, and a rectangle using the FillEllipse, FillPie, and FillRectangle methods of the Graphics class, respectively. SolidBrush has only one property of interest: Color, which represents the color of the brush. SolidBrush blueBrush = new SolidBrush(Color.Blue) SolidBrush greenBrush = new SolidBrush(Color.Green) The code snippet in Listing 4.2 creates three SolidBrush objects with three different colors: red, green, and blue. For example, Color.Red represents the color red. It has a static property for every possible color. We create a SolidBrush object by calling its constructor and passing a Color structure as the only parameter. For instance, the Brushes.Pink, Brushes.Red, and Brushes.Green members represent Brush objects with the colors pink, red, and green, respectively.Ī solid brush is a brush that fills an area with a single solid color. Brushes provides more than 140 static members (properties), and each of these members represents a brush with a particular color (including all the standard colors). The Brushes class is a sealed class (it cannot be inherited). Figure 4.2 shows the brush types and their classes.įigure 4.2. GDI+ provides four different kinds of brushes: solid, hatch, texture, and gradient. Classes inherited from the Brush classĪpplications generally call fill methods of the appropriate Graphics class, which in turn use brushes to fill GDI+ objects (such as an ellipse, an arc, or a polygon) with a certain kind of brush. Figure 4.1 shows all the Brush-derived classes that can be used in your GDI+ applications.įigure 4.1. All usable classes are inherited from the abstract Brush class. NET Framework library, the Brush class is an abstract base class, which means you cannot create an instance of it without using its derived classes. SolidBrush redBrush = new SolidBrush(Color.Red) The last line disposes of the SolidBrush object. The first line gets the Graphics object of the form, and the second line creates a brush using the SolidBrush class, which later is used to fill a rectangle. This code is written on a form's paint event handler. The code snippet in Listing 4.1 creates a red SolidBrush object and uses it to draw a rectangle.

Alternatively, you can use the namespace as a prefix to the class for example, represents the Brush class if you do not wish to include the System.Drawing namespace in your application. For example, the Brush, SolidBrush, TextureBrush, and Brushes classes are defined in the System.Drawing namespace and the HatchBrush and GradientBrush classes are defined in the 2D namespace.īefore using brushes, obviously you must include the corresponding namespace to your application. The System.Drawing namespace defines general brush-related classes and functionality, and the 2D namespace defines advanced 2D brush-related functionality. NET Framework library, brush-related functionality is defined in two namespaces: System.Drawing and 2D.
