Brush Objects in Visual Studio .NET

Generator QR Code ISO/IEC18004 in Visual Studio .NET Brush Objects

Brush Objects
Making QR In .NET
Using Barcode generation for .NET Control to generate, create QR image in Visual Studio .NET applications.
www.OnBarcode.com
QR Code JIS X 0510 Scanner In .NET Framework
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
All the examples I ve shown you so far use one of the predefined Brush objects exposed as properties of the Brushes or the SystemBrushes class. You can create a custom brush by using one of the many available classes in the GDI+ subsystem. The most notable dif ference between custom and predefined brushes is that you must dispose of your custom brushes before you set them to Nothing or let them go out of scope. The simplest type of custom brush is the SolidBrush object, whose constructor takes a color:
Make Barcode In VS .NET
Using Barcode generation for Visual Studio .NET Control to generate, create bar code image in Visual Studio .NET applications.
www.OnBarcode.com
Decode Barcode In .NET Framework
Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Create a solid brush with a custom color, and use it to fill a rectangle.
Create QR Code In Visual C#.NET
Using Barcode generator for VS .NET Control to generate, create QR Code image in .NET framework applications.
www.OnBarcode.com
Create QR Code JIS X 0510 In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create QR Code image in ASP.NET applications.
www.OnBarcode.com
Dim br As New SolidBrush(Color.FromArgb(128, 30, 100))
QR Code Creation In VB.NET
Using Barcode generator for .NET framework Control to generate, create QR image in .NET applications.
www.OnBarcode.com
Painting DataMatrix In VS .NET
Using Barcode drawer for .NET Control to generate, create Data Matrix 2d barcode image in .NET applications.
www.OnBarcode.com
gr.FillRectangle(br, New Rectangle(10, 10, 200, 100))
Barcode Drawer In .NET
Using Barcode creator for .NET framework Control to generate, create barcode image in .NET applications.
www.OnBarcode.com
PDF417 Creator In .NET Framework
Using Barcode maker for .NET Control to generate, create PDF-417 2d barcode image in .NET framework applications.
www.OnBarcode.com
Destroy the brush.
Generating Barcode In VS .NET
Using Barcode drawer for Visual Studio .NET Control to generate, create barcode image in .NET framework applications.
www.OnBarcode.com
USPS OneCode Solution Barcode Creation In .NET
Using Barcode drawer for .NET framework Control to generate, create USPS OneCode Solution Barcode image in VS .NET applications.
www.OnBarcode.com
br.Dispose()
Barcode Creation In None
Using Barcode encoder for Office Excel Control to generate, create barcode image in Office Excel applications.
www.OnBarcode.com
Encode Code 128C In None
Using Barcode creation for Excel Control to generate, create Code 128 image in Office Excel applications.
www.OnBarcode.com
17:
Drawing Code39 In None
Using Barcode creation for Online Control to generate, create Code 39 image in Online applications.
www.OnBarcode.com
EAN 13 Creation In Java
Using Barcode generation for BIRT reports Control to generate, create GTIN - 13 image in BIRT applications.
www.OnBarcode.com
GDI+
Scan Barcode In Visual Studio .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
UPC-A Recognizer In .NET Framework
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
The HatchBrush class (in the System.Drawing.Drawing2D namespace) is a simple way to create two-color brushes that use one of the 56 predefined motifs available. The follow ing listing shows the code that generates the upper left hatched rectangle in Figure 17-7:
Decoding Universal Product Code Version A In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
PDF-417 2d Barcode Printer In Java
Using Barcode printer for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
Dim br1 As New HatchBrush(HatchStyle.BackwardDiagonal, _ Color.White, Color.Blue) gr.FillRectangle(br1, New Rectangle(10, 10, 200, 100)) br1.Dispose()
Figure 17-7
Six of the 56 available styles for hatch brushes
The LinearGradientBrush class represents a gradient brush, that is, a brush that con tains all the color nuances that vary from a starting color to an ending color, like the typical background screen of many installation procedures or Microsoft PowerPoint slides. The simplest way to create a linear gradient brush is to pass its size (by means of a Rectangle object), the two colors, and a direction to the brush s constructor. You can then use this brush to paint any filled shape:
Dim br As New LinearGradientBrush(New Rectangle(0, 0, 200, 100), _ Color.Blue, Color.Black, LinearGradientMode.ForwardDiagonal) gr.FillRectangle(br, 0, 0, 200, 100) gr.FillRectangle(br, 220, 0, 200, 100) br.Dispose()
The constructor that you see in the preceding code lets you indicate four directions for the gradient: horizontal, vertical, forward diagonal, and backward diagonal. If the shape being painted is larger than the brush rectangle, the brush is tiled to cover the shape. If the shape s coordinates aren t exact multiples of the rectangle s size, the color of the shape s upper left corner won t coincide with the brush s first color, as is the case with the
Part IV:
Win32 Applications
rightmost rectangle in Figure 17-8 (which shows the outcome of the preceding code snippet). You can influence how the brush is used to fill the shape by using the WrapMode property, which can be Tile (the default), TileFlipX, TileFlipY, TileFlipXY, or Clamp.
Figure 17-8
Two rectangles painted with linear gradient brushes
By default, this type of brush uses a linear gradient, in which intermediate pixels change linearly from starting to ending color. However, you can use the Blend prop erty to define a nonlinear progression. (See the .NET Platform SDK for more details about nonlinear gradient brushes.) Yet another type of brush is the TextureBrush class, whose constructor takes an Image object and an optional argument that tells how the image must be tiled if the painted shape is larger than the image. By default, the image is tiled as is, but you can also decide to flip it on the horizontal axis, the vertical axis, or both, as the following code illustrates. (See Figure 17-9.)
These examples use a bitmap loaded in a PictureBox control. Dim br1 As New TextureBrush(PictureBox1.Image) gr.FillRectangle(br1, New Rectangle(20, 20, 250, 150)) br1.Dispose() Dim br2 As New TextureBrush(PictureBox1.Image, WrapMode.TileFlipY) gr.FillRectangle(br2, New Rectangle(300, 20, 250, 150)) br2.Dispose() Dim br3 As New TextureBrush(PictureBox1.Image, WrapMode.TileFlipX) gr.FillRectangle(br3, New Rectangle(20, 220, 250, 150)) br3.Dispose() Dim br4 As New TextureBrush(PictureBox1.Image, WrapMode.TileFlipXY) gr.FillRectangle(br4, New Rectangle(300, 220, 250, 150)) br4.Dispose()
The final type of brush class to be examined is PathGradientBrush, which patterns a gradient brush after a GraphicsPath object. Unlike other rectangular brushes, which are automatically tiled to cover surfaces of any size and shape, this type of brush doesn t extend over the boundaries of the path object used to define it, and in practice it should be used only to paint a specific path surface. In its simplest form, a PathGradi entBrush is defined by a GraphicsPath object, the color of the center point, and the color at the path s borders:
17:
Copyright © OnBarcode.com . All rights reserved.