GDI+ Hatch Brushes |
|
Introduction |
A hatch brush relies on a drawn or designed pattern to set its filling type. To support hatch brushes, the .NET Framework provides the patterns you can use as part of the brush. These pre-designed patterns are referred to as hatch styles. This means that when you use a hatch brush, you must specify the type of pattern you want to use, through one of the available hatch styles. To make the filled area more interesting, you also specify the color to use when drawing the pattern. To get a hatch brush, you use the HatchBrush class. One of its constructors has the following syntaxes: |
Public Sub New(hatchstyle As HatchStyle, foreColor As Color)
The foreColor argument is the color that will be used to draw the pattern. The style argument is the hatch style you want to apply. Some of the available styles are: Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms Module Exercise Public Class Starter Inherits Form Dim components As System.ComponentModel.Container Public Sub New() InitializeComponent() End Sub Public Sub InitializeComponent() End Sub Private Sub FormPaint(ByVal sender As Object, _ ByVal e As PaintEventArgs) _ Handles MyBase.Paint Dim brushBackDiag As HatchBrush = _ New HatchBrush(HatchStyle.BackwardDiagonal, _ Color.FromArgb(0, 0, 255)) Dim brushCross As HatchBrush = _ New HatchBrush(HatchStyle.Cross, _ Color.FromArgb(200, 0, 0)) Dim brushDarkDown As HatchBrush = _ New HatchBrush(HatchStyle.DarkDownwardDiagonal, _ Color.Salmon) Dim brushDarkHorz As HatchBrush = _ New HatchBrush(HatchStyle.DarkHorizontal, _ Color.Navy) Dim brushDarkUpDiag As HatchBrush = _ New HatchBrush(HatchStyle.DarkUpwardDiagonal, _ Color.Pink) Dim brushVertical As HatchBrush = _ New HatchBrush(HatchStyle.DarkVertical, _ Color.FromArgb(255, 0, 255)) Dim brushDashDnDiag As HatchBrush = _ New HatchBrush(HatchStyle.DashedDownwardDiagonal, _ Color.FromArgb(255, 128, 0)) Dim brushDashHorz As HatchBrush = _ New HatchBrush(HatchStyle.DashedHorizontal, _ Color.FromArgb(0, 128, 192)) Dim brushDashUpDiag As HatchBrush = _ New HatchBrush(HatchStyle.DashedUpwardDiagonal, _ Color.Green) Dim brushDashVert As HatchBrush = _ New HatchBrush(HatchStyle.DashedVertical, _ Color.Firebrick) Dim brushDiagBrisk As HatchBrush = _ New HatchBrush(HatchStyle.DiagonalBrick, _ Color.Fuchsia) Dim brushDiagCross As HatchBrush = _ New HatchBrush(HatchStyle.DiagonalCross, _ Color.Moccasin) Dim brushDivot As HatchBrush = _ New HatchBrush(HatchStyle.Divot, _ Color.Goldenrod) Dim brushDotDiamond As HatchBrush = _ New HatchBrush(HatchStyle.DottedDiamond, _ Color.Gainsboro) Dim brushDottedGrid As HatchBrush = _ New HatchBrush(HatchStyle.DottedGrid, _ Color.Khaki) Dim brushForDiag As HatchBrush = _ New HatchBrush(HatchStyle.ForwardDiagonal, _ Color.Maroon) Dim brushHorz As HatchBrush = _ New HatchBrush(HatchStyle.Horizontal, _ Color.Red) Dim brushHorzBrick As HatchBrush = _ New HatchBrush(HatchStyle.HorizontalBrick, _ Color.SaddleBrown) Dim brushLgChkBoard As HatchBrush = _ New HatchBrush(HatchStyle.LargeCheckerBoard, _ Color.RoyalBlue) Dim brushLgConfetti As HatchBrush = _ New HatchBrush(HatchStyle.LargeConfetti, _ Color.MistyRose) Dim brushLgGrid As HatchBrush = _ New HatchBrush(HatchStyle.LargeGrid, _ Color.Purple) Dim brushLtDnDiag As HatchBrush = _ New HatchBrush(HatchStyle.LightDownwardDiagonal, _ Color.DarkCyan) Dim brushLtHorz As HatchBrush = _ New HatchBrush(HatchStyle.LightHorizontal, _ Color.PowderBlue) Dim brushUpDiag As HatchBrush = _ New HatchBrush(HatchStyle.LightUpwardDiagonal, _ Color.SeaGreen) Dim brushLtVert As HatchBrush = _ New HatchBrush(HatchStyle.LightVertical, _ Color.Olive) e.Graphics.FillRectangle(brushBackDiag, _ 20, 20, 80, 60) e.Graphics.FillRectangle(brushCross, _ 120, 20, 80, 60) e.Graphics.FillRectangle(brushDarkDown, _ 220, 20, 80, 60) e.Graphics.FillRectangle(brushDarkHorz, _ 320, 20, 80, 60) e.Graphics.FillRectangle(brushDarkUpDiag, _ 420, 20, 80, 60) e.Graphics.FillRectangle(brushVertical, _ 20, 100, 80, 60) e.Graphics.FillRectangle(brushDashDnDiag, _ 120, 100, 80, 60) e.Graphics.FillRectangle(brushDashHorz, _ 220, 100, 80, 60) e.Graphics.FillRectangle(brushDashUpDiag, _ 320, 100, 80, 60) e.Graphics.FillRectangle(brushDashVert, _ 420, 100, 80, 60) e.Graphics.FillRectangle(brushDashVert, _ 20, 180, 80, 60) e.Graphics.FillRectangle(brushDiagBrisk, _ 120, 180, 80, 60) e.Graphics.FillRectangle(brushDiagCross, _ 220, 180, 80, 60) e.Graphics.FillRectangle(brushDivot, _ 320, 180, 80, 60) e.Graphics.FillRectangle(brushDotDiamond, _ 420, 180, 80, 60) e.Graphics.FillRectangle(brushDottedGrid, _ 20, 260, 80, 60) e.Graphics.FillRectangle(brushForDiag, _ 120, 260, 80, 60) e.Graphics.FillRectangle(brushHorz, _ 220, 260, 80, 60) e.Graphics.FillRectangle(brushHorzBrick, _ 320, 260, 80, 60) e.Graphics.FillRectangle(brushLgChkBoard, _ 420, 260, 80, 60) e.Graphics.FillRectangle(brushLgGrid, _ 20, 340, 80, 60) e.Graphics.FillRectangle(brushLtDnDiag, _ 120, 340, 80, 60) e.Graphics.FillRectangle(brushLtHorz, _ 220, 340, 80, 60) e.Graphics.FillRectangle(brushUpDiag, _ 320, 340, 80, 60) e.Graphics.FillRectangle(brushLtVert, _ 420, 340, 80, 60) End Sub End Class Function Main() As Integer Dim frmStart As Starter = New Starter Application.Run(frmStart) Return 0 End Function End Module This would produce:
|
|
||
Home | Copyright © 2008-2016, FunctionX, Inc. | Home |
|