We've now come to the conclusion that different groups of people are in charge of developing different technologies over at Microsoft. The WPF (Windows Presentation Foundation) development team made a significant number of improvements over Windows Forms and GDI+, but in the process missed a couple of things.
One very important item is the System.Drawing.HatchBrush from System.Drawing.Drawing2D which was very useful in Windows Forms but is now totally absent in WPF. We have made an interim replacement, which although does not use the win32 API directly should provide a remedy for most situations.
If used conservatively it should not have that much of an impact on the performance of your WPF applications.
This code draws hatches in Windows Forms:
Public Class Form1 Inherits System.Windows.Forms.Form Dim mp_oGraphics As System.Drawing.Graphics Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) mp_oGraphics = e.Graphics Dim i As Integer Dim j As Integer j = 0 For i = 0 To 9 HatchFill(0, j * 30, 100, (j * 30) + 20, Color.Black, Color.White, i) j = j + 1 Next j = 0 For i = 10 To 19 HatchFill(120, j * 30, 220, (j * 30) + 20, Color.Black, Color.White, i) j = j + 1 Next j = 0 For i = 20 To 29 HatchFill(240, j * 30, 340, (j * 30) + 20, Color.Black, Color.White, i) j = j + 1 Next j = 0 For i = 30 To 39 HatchFill(360, j * 30, 460, (j * 30) + 20, Color.Black, Color.White, i) j = j + 1 Next j = 0 For i = 40 To 49 HatchFill(480, j * 30, 580, (j * 30) + 20, Color.Black, Color.White, i) j = j + 1 Next j = 0 For i = 50 To 52 HatchFill(600, j * 30, 700, (j * 30) + 20, Color.Black, Color.White, i) j = j + 1 Next End Sub Public Sub HatchFill(ByVal v_X1 As Integer, ByVal v_Y1 As Integer, ByVal v_X2 As Integer, ByVal v_Y2 As Integer, ByVal clrForeColor As Color, ByVal clrBackColor As Color, ByVal yHatchStyle As Integer) Dim mp_ucBrush As System.Drawing.Drawing2D.HatchBrush mp_ucBrush = New System.Drawing.Drawing2D.HatchBrush(yHatchStyle, clrForeColor, clrBackColor) Dim Points(4) As Point Points(0).X = v_X1 Points(0).Y = v_Y1 Points(1).X = v_X2 + 1 Points(1).Y = v_Y1 Points(2).X = v_X2 + 1 Points(2).Y = v_Y2 + 1 Points(3).X = v_X1 Points(3).Y = v_Y2 + 1 Points(4).X = v_X1 Points(4).Y = v_Y1 mp_oGraphics.FillPolygon(mp_ucBrush, Points) End Sub End Class
And produces this output:
WPF does not use the OnPaint override like GDI+. Instead you have to override the OnRender method. One important thing to note however is that WPF will disregard any drawing made to the DrawingContext unless the background mode is set to transparent, so the XAML for the Window should look like this:
<Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="404" Width="727" Background="Transparent"> </Window>
And this is the WPF code for drawing Windows Forms style Hatches:
Class Window1 Private mp_oGraphics As DrawingContext Private Enum T_HATCHTYPE HT_RECTANGLE = 1 HT_LINE = 2 End Enum Private Enum GRE_HATCHSTYLE HS_HORIZONTAL = 0 HS_VERTICAL = 1 HS_FORWARDDIAGONAL = 2 HS_BACKWARDDIAGONAL = 3 HS_LARGEGRID = 4 HS_DIAGONALCROSS = 5 HS_PERCENT05 = 6 HS_PERCENT10 = 7 HS_PERCENT20 = 8 HS_PERCENT25 = 9 HS_PERCENT30 = 10 HS_PERCENT40 = 11 HS_PERCENT50 = 12 HS_PERCENT60 = 13 HS_PERCENT70 = 14 HS_PERCENT75 = 15 HS_PERCENT80 = 16 HS_PERCENT90 = 17 HS_LIGHTDOWNWARDDIAGONAL = 18 HS_LIGHTUPWARDDIAGONAL = 19 HS_DARKDOWNWARDDIAGONAL = 20 HS_DARKUPWARDDIAGONAL = 21 HS_WIDEDOWNWARDDIAGONAL = 22 HS_WIDEUPWARDDIAGONAL = 23 HS_LIGHTVERTICAL = 24 HS_LIGHTHORIZONTAL = 25 HS_NARROWVERTICAL = 26 HS_NARROWHORIZONTAL = 27 HS_DARKVERTICAL = 28 HS_DARKHORIZONTAL = 29 HS_DASHEDDOWNWARDDIAGONAL = 30 HS_DASHEDUPWARDDIAGONAL = 31 HS_DASHEDHORIZONTAL = 32 HS_DASHEDVERTICAL = 33 HS_SMALLCONFETTI = 34 HS_LARGECONFETTI = 35 HS_ZIGZAG = 36 HS_WAVE = 37 HS_DIAGONALBRICK = 38 HS_HORIZONTALBRICK = 39 HS_WEAVE = 40 HS_PLAID = 41 HS_DIVOT = 42 HS_DOTTEDGRID = 43 HS_DOTTEDDIAMOND = 44 HS_SHINGLE = 45 HS_TRELLIS = 46 HS_SPHERE = 47 HS_SMALLGRID = 48 HS_SMALLCHECKERBOARD = 49 HS_LARGECHECKERBOARD = 50 HS_OUTLINEDDIAMOND = 51 HS_SOLIDDIAMOND = 52 End Enum Protected Overrides Sub OnRender(ByVal oDC As DrawingContext) mp_oGraphics = oDC mp_oGraphics.DrawRectangle(Brushes.DarkGray, Nothing, New Rect(New Point(0, 0), New Point(Me.Width, Me.Height))) Dim i As Integer Dim j As Integer j = 0 For i = 0 To 9 HatchFill(0, j * 30, 100, (j * 30) + 20, Colors.Black, Colors.White, i) j = j + 1 Next j = 0 For i = 10 To 19 HatchFill(120, j * 30, 220, (j * 30) + 20, Colors.Black, Colors.White, i) j = j + 1 Next j = 0 For i = 20 To 29 HatchFill(240, j * 30, 340, (j * 30) + 20, Colors.Black, Colors.White, i) j = j + 1 Next j = 0 For i = 30 To 39 HatchFill(360, j * 30, 460, (j * 30) + 20, Colors.Black, Colors.White, i) j = j + 1 Next j = 0 For i = 40 To 49 HatchFill(480, j * 30, 580, (j * 30) + 20, Colors.Black, Colors.White, i) j = j + 1 Next j = 0 For i = 50 To 52 HatchFill(600, j * 30, 700, (j * 30) + 20, Colors.Black, Colors.White, i) j = j + 1 Next End Sub Public Sub HatchFill(ByVal v_X1 As Integer, ByVal v_Y1 As Integer, ByVal v_X2 As Integer, ByVal v_Y2 As Integer, ByVal clrForeColor As Color, ByVal clrBackColor As Color, ByVal yHatchStyle As Integer) Dim mp_ucBrush As DrawingBrush mp_ucBrush = GetHatchBrush(yHatchStyle, clrForeColor, clrBackColor) Dim iBuff As Integer = 0 If (v_X2 - v_X1) <= 0 Then iBuff = v_X1 v_X1 = v_X2 v_X2 = iBuff End If If (v_Y2 - v_Y1) <= 0 Then iBuff = v_Y1 v_Y1 = v_Y2 v_Y2 = iBuff End If mp_oGraphics.DrawRectangle(mp_ucBrush, Nothing, New Rect(v_X1, v_Y1, v_X2 - v_X1 + 1, v_Y2 - v_Y1 + 1)) End Sub Private Function GetHatchBrush(ByVal yHatchStyle As GRE_HATCHSTYLE, ByVal clrForeColor As Color, ByVal clrBackColor As Color) Dim oReturnBrush As New DrawingBrush Dim oHatchGroup As New GeometryGroup() Dim oHatchCtrlGroup As New GeometryGroup() Dim Width As Integer = 0 Dim Height As Integer = 0 Dim yType As T_HATCHTYPE = T_HATCHTYPE.HT_LINE Dim bAliased As Boolean = True Select Case yHatchStyle Case GRE_HATCHSTYLE.HS_HORIZONTAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(0, 0, 7, 0)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_VERTICAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(0, 0, 0, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_FORWARDDIAGONAL Width = 16 Height = 16 oHatchGroup.Children.Add(mp_GLine(0, 12, 3, 15)) oHatchGroup.Children.Add(mp_GLine(0, 4, 11, 15)) oHatchGroup.Children.Add(mp_GLine(4, 0, 15, 11)) oHatchGroup.Children.Add(mp_GLine(12, 0, 15, 3)) System.Diagnostics.Debug.Write(oHatchGroup) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_BACKWARDDIAGONAL Width = 16 Height = 16 oHatchGroup.Children.Add(mp_GLine(0, 12, 3, 15)) oHatchGroup.Children.Add(mp_GLine(0, 4, 11, 15)) oHatchGroup.Children.Add(mp_GLine(4, 0, 15, 11)) oHatchGroup.Children.Add(mp_GLine(12, 0, 15, 3)) oHatchGroup.Transform = New RotateTransform(90, 8, 8) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_LARGEGRID Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(0, 0, 7, 0)) oHatchGroup.Children.Add(mp_GLine(0, 0, 0, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DIAGONALCROSS Width = 7 Height = 7 oHatchGroup.Children.Add(mp_GRect(1, 1, 5, 5)) oHatchGroup.Transform = New RotateTransform(45, 3, 3) yType = T_HATCHTYPE.HT_LINE bAliased = False Case GRE_HATCHSTYLE.HS_PERCENT05 Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 4)) oHatchGroup.Children.Add(mp_GPoint(4, 0)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT10 Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(4, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 6)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT20 Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT25 Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(2, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT30 Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) oHatchGroup.Children.Add(mp_GPoint(2, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT40 Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(2, 0)) oHatchGroup.Children.Add(mp_GPoint(4, 0)) oHatchGroup.Children.Add(mp_GPoint(6, 0)) oHatchGroup.Children.Add(mp_GPoint(3, 1)) oHatchGroup.Children.Add(mp_GPoint(5, 1)) oHatchGroup.Children.Add(mp_GPoint(7, 1)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(4, 2)) oHatchGroup.Children.Add(mp_GPoint(6, 2)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) oHatchGroup.Children.Add(mp_GPoint(5, 3)) oHatchGroup.Children.Add(mp_GPoint(7, 3)) oHatchGroup.Children.Add(mp_GPoint(0, 4)) oHatchGroup.Children.Add(mp_GPoint(2, 4)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) oHatchGroup.Children.Add(mp_GPoint(6, 4)) oHatchGroup.Children.Add(mp_GPoint(1, 5)) oHatchGroup.Children.Add(mp_GPoint(3, 5)) oHatchGroup.Children.Add(mp_GPoint(7, 5)) oHatchGroup.Children.Add(mp_GPoint(0, 6)) oHatchGroup.Children.Add(mp_GPoint(2, 6)) oHatchGroup.Children.Add(mp_GPoint(4, 6)) oHatchGroup.Children.Add(mp_GPoint(6, 6)) oHatchGroup.Children.Add(mp_GPoint(1, 7)) oHatchGroup.Children.Add(mp_GPoint(3, 7)) oHatchGroup.Children.Add(mp_GPoint(5, 7)) oHatchGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT50 Width = 2 Height = 2 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT60 Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(2, 0)) oHatchGroup.Children.Add(mp_GPoint(3, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(3, 1)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(1, 2)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT70 Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(1, 0)) oHatchGroup.Children.Add(mp_GPoint(2, 0)) oHatchGroup.Children.Add(mp_GPoint(3, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 1)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(3, 1)) oHatchGroup.Children.Add(mp_GPoint(1, 2)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(3, 2)) oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT75 Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(2, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) InvertColors(clrForeColor, clrBackColor) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT80 Width = 8 Height = 7 oHatchGroup.Children.Add(mp_GPoint(3, 0)) oHatchGroup.Children.Add(mp_GPoint(3, 4)) oHatchGroup.Children.Add(mp_GPoint(7, 2)) oHatchGroup.Children.Add(mp_GPoint(7, 6)) InvertColors(clrForeColor, clrBackColor) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PERCENT90 Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 5)) oHatchGroup.Children.Add(mp_GPoint(4, 1)) InvertColors(clrForeColor, clrBackColor) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_LIGHTDOWNWARDDIAGONAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_LIGHTUPWARDDIAGONAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GPoint(1, 2)) oHatchGroup.Children.Add(mp_GPoint(2, 1)) oHatchGroup.Children.Add(mp_GPoint(3, 0)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DARKDOWNWARDDIAGONAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) oHatchGroup.Children.Add(mp_GPoint(1, 0)) oHatchGroup.Children.Add(mp_GPoint(2, 1)) oHatchGroup.Children.Add(mp_GPoint(3, 2)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DARKUPWARDDIAGONAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 1)) oHatchGroup.Children.Add(mp_GPoint(1, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(3, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 2)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_WIDEDOWNWARDDIAGONAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(3, 0, 5, 0)) oHatchGroup.Children.Add(mp_GLine(4, 1, 6, 1)) oHatchGroup.Children.Add(mp_GLine(5, 2, 7, 2)) oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GLine(6, 3, 7, 3)) oHatchGroup.Children.Add(mp_GLine(0, 4, 1, 4)) oHatchGroup.Children.Add(mp_GPoint(7, 4)) oHatchGroup.Children.Add(mp_GLine(0, 5, 2, 5)) oHatchGroup.Children.Add(mp_GLine(1, 6, 3, 6)) oHatchGroup.Children.Add(mp_GLine(2, 7, 4, 7)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_WIDEUPWARDDIAGONAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(4, 0, 6, 0)) oHatchGroup.Children.Add(mp_GLine(3, 1, 5, 1)) oHatchGroup.Children.Add(mp_GLine(2, 2, 4, 2)) oHatchGroup.Children.Add(mp_GLine(1, 3, 3, 3)) oHatchGroup.Children.Add(mp_GLine(0, 4, 2, 4)) oHatchGroup.Children.Add(mp_GLine(0, 5, 1, 5)) oHatchGroup.Children.Add(mp_GPoint(7, 5)) oHatchGroup.Children.Add(mp_GPoint(0, 6)) oHatchGroup.Children.Add(mp_GLine(6, 6, 7, 6)) oHatchGroup.Children.Add(mp_GLine(5, 7, 7, 7)) oHatchCtrlGroup.Children.Add(mp_GLine(0, 0, 7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_LIGHTVERTICAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GLine(0, 0, 0, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_LIGHTHORIZONTAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GLine(0, 0, 3, 0)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_NARROWVERTICAL Width = 2 Height = 2 oHatchGroup.Children.Add(mp_GLine(1, 0, 1, 1)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_NARROWHORIZONTAL Width = 2 Height = 2 oHatchGroup.Children.Add(mp_GLine(0, 1, 1, 1)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DARKVERTICAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GLine(0, 0, 0, 3)) oHatchGroup.Children.Add(mp_GLine(1, 0, 1, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DARKHORIZONTAL Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GLine(0, 0, 3, 0)) oHatchGroup.Children.Add(mp_GLine(0, 1, 3, 1)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DASHEDDOWNWARDDIAGONAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(2, 4)) oHatchGroup.Children.Add(mp_GPoint(3, 5)) oHatchGroup.Children.Add(mp_GPoint(4, 2)) oHatchGroup.Children.Add(mp_GPoint(5, 3)) oHatchGroup.Children.Add(mp_GPoint(6, 4)) oHatchGroup.Children.Add(mp_GPoint(7, 5)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DASHEDUPWARDDIAGONAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 7)) oHatchGroup.Children.Add(mp_GPoint(1, 6)) oHatchGroup.Children.Add(mp_GPoint(2, 5)) oHatchGroup.Children.Add(mp_GPoint(3, 4)) oHatchGroup.Children.Add(mp_GPoint(4, 7)) oHatchGroup.Children.Add(mp_GPoint(5, 6)) oHatchGroup.Children.Add(mp_GPoint(6, 5)) oHatchGroup.Children.Add(mp_GPoint(7, 4)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DASHEDHORIZONTAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(4, 0, 7, 0)) oHatchGroup.Children.Add(mp_GLine(0, 4, 3, 4)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DASHEDVERTICAL Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(0, 0, 0, 1)) oHatchGroup.Children.Add(mp_GLine(0, 6, 0, 7)) oHatchGroup.Children.Add(mp_GLine(4, 2, 4, 5)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_SMALLCONFETTI Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(4, 1)) oHatchGroup.Children.Add(mp_GPoint(1, 2)) oHatchGroup.Children.Add(mp_GPoint(6, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 4)) oHatchGroup.Children.Add(mp_GPoint(7, 5)) oHatchGroup.Children.Add(mp_GPoint(2, 6)) oHatchGroup.Children.Add(mp_GPoint(5, 7)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_LARGECONFETTI Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(0, 1, 0, 2)) oHatchGroup.Children.Add(mp_GLine(0, 6, 0, 7)) oHatchGroup.Children.Add(mp_GLine(1, 6, 1, 7)) oHatchGroup.Children.Add(mp_GLine(2, 2, 2, 3)) oHatchGroup.Children.Add(mp_GLine(3, 2, 3, 3)) oHatchGroup.Children.Add(mp_GLine(3, 5, 3, 6)) oHatchGroup.Children.Add(mp_GLine(4, 0, 4, 1)) oHatchGroup.Children.Add(mp_GLine(4, 5, 4, 6)) oHatchGroup.Children.Add(mp_GLine(5, 0, 5, 1)) oHatchGroup.Children.Add(mp_GLine(6, 4, 6, 5)) oHatchGroup.Children.Add(mp_GLine(7, 1, 7, 2)) oHatchGroup.Children.Add(mp_GLine(7, 4, 7, 5)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_ZIGZAG Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GLine(3, 3, 4, 3)) oHatchGroup.Children.Add(mp_GPoint(5, 2)) oHatchGroup.Children.Add(mp_GPoint(6, 1)) oHatchGroup.Children.Add(mp_GPoint(7, 0)) oHatchGroup.Children.Add(mp_GPoint(0, 4)) oHatchGroup.Children.Add(mp_GPoint(1, 5)) oHatchGroup.Children.Add(mp_GPoint(2, 6)) oHatchGroup.Children.Add(mp_GLine(3, 7, 4, 7)) oHatchGroup.Children.Add(mp_GPoint(5, 6)) oHatchGroup.Children.Add(mp_GPoint(6, 5)) oHatchGroup.Children.Add(mp_GPoint(7, 4)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_WAVE Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(2, 0)) oHatchGroup.Children.Add(mp_GPoint(5, 0)) oHatchGroup.Children.Add(mp_GPoint(7, 0)) oHatchGroup.Children.Add(mp_GLine(0, 2, 1, 2)) oHatchGroup.Children.Add(mp_GLine(3, 4, 4, 4)) oHatchGroup.Children.Add(mp_GPoint(2, 4)) oHatchGroup.Children.Add(mp_GPoint(5, 4)) oHatchGroup.Children.Add(mp_GPoint(7, 4)) oHatchGroup.Children.Add(mp_GLine(0, 6, 1, 6)) oHatchGroup.Children.Add(mp_GLine(3, 8, 4, 8)) oHatchCtrlGroup.Children.Add(mp_GPoint(0, 0)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DIAGONALBRICK Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 7)) oHatchGroup.Children.Add(mp_GPoint(1, 6)) oHatchGroup.Children.Add(mp_GPoint(2, 5)) oHatchGroup.Children.Add(mp_GPoint(3, 4)) oHatchGroup.Children.Add(mp_GPoint(4, 3)) oHatchGroup.Children.Add(mp_GPoint(5, 2)) oHatchGroup.Children.Add(mp_GPoint(6, 1)) oHatchGroup.Children.Add(mp_GPoint(7, 0)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) oHatchGroup.Children.Add(mp_GPoint(5, 5)) oHatchGroup.Children.Add(mp_GPoint(6, 6)) oHatchGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_HORIZONTALBRICK Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(4, 0)) oHatchGroup.Children.Add(mp_GPoint(4, 1)) oHatchGroup.Children.Add(mp_GLine(0, 1, 0, 5)) oHatchGroup.Children.Add(mp_GPoint(4, 6)) oHatchGroup.Children.Add(mp_GPoint(4, 7)) oHatchGroup.Children.Add(mp_GLine(1, 2, 7, 2)) oHatchGroup.Children.Add(mp_GLine(1, 6, 7, 6)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_WEAVE Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(1, 1)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(0, 4)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 1)) oHatchGroup.Children.Add(mp_GPoint(4, 0)) oHatchGroup.Children.Add(mp_GPoint(5, 1)) oHatchGroup.Children.Add(mp_GPoint(6, 2)) oHatchGroup.Children.Add(mp_GPoint(7, 3)) oHatchGroup.Children.Add(mp_GPoint(5, 3)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) oHatchGroup.Children.Add(mp_GPoint(3, 5)) oHatchGroup.Children.Add(mp_GPoint(2, 6)) oHatchGroup.Children.Add(mp_GPoint(1, 7)) oHatchGroup.Children.Add(mp_GPoint(3, 7)) oHatchGroup.Children.Add(mp_GPoint(5, 5)) oHatchGroup.Children.Add(mp_GPoint(6, 6)) oHatchGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_PLAID Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(0, 0, 3, 0)) oHatchGroup.Children.Add(mp_GLine(0, 1, 3, 1)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(4, 2)) oHatchGroup.Children.Add(mp_GPoint(6, 2)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) oHatchGroup.Children.Add(mp_GPoint(5, 3)) oHatchGroup.Children.Add(mp_GPoint(7, 3)) oHatchGroup.Children.Add(mp_GPoint(0, 4)) oHatchGroup.Children.Add(mp_GPoint(2, 4)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) oHatchGroup.Children.Add(mp_GPoint(6, 4)) oHatchGroup.Children.Add(mp_GPoint(1, 5)) oHatchGroup.Children.Add(mp_GPoint(3, 5)) oHatchGroup.Children.Add(mp_GPoint(5, 5)) oHatchGroup.Children.Add(mp_GPoint(7, 5)) oHatchGroup.Children.Add(mp_GLine(0, 6, 3, 6)) oHatchGroup.Children.Add(mp_GLine(0, 7, 3, 7)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DIVOT Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 1)) oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 5)) oHatchGroup.Children.Add(mp_GPoint(3, 7)) oHatchGroup.Children.Add(mp_GPoint(4, 6)) oHatchGroup.Children.Add(mp_GPoint(7, 2)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DOTTEDGRID Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(1, 6)) oHatchGroup.Children.Add(mp_GPoint(3, 6)) oHatchGroup.Children.Add(mp_GPoint(5, 6)) oHatchGroup.Children.Add(mp_GPoint(7, 6)) oHatchGroup.Children.Add(mp_GPoint(7, 4)) oHatchGroup.Children.Add(mp_GPoint(7, 2)) oHatchGroup.Children.Add(mp_GPoint(7, 0)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_DOTTEDDIAMOND Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 0)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) oHatchGroup.Children.Add(mp_GPoint(6, 6)) oHatchGroup.Children.Add(mp_GPoint(2, 6)) oHatchGroup.Children.Add(mp_GPoint(6, 2)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_SHINGLE Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GPoint(1, 4)) oHatchGroup.Children.Add(mp_GPoint(2, 5)) oHatchGroup.Children.Add(mp_GPoint(3, 5)) oHatchGroup.Children.Add(mp_GPoint(4, 6)) oHatchGroup.Children.Add(mp_GPoint(5, 6)) oHatchGroup.Children.Add(mp_GPoint(6, 7)) oHatchGroup.Children.Add(mp_GPoint(4, 4)) oHatchGroup.Children.Add(mp_GPoint(5, 3)) oHatchGroup.Children.Add(mp_GPoint(6, 2)) oHatchGroup.Children.Add(mp_GPoint(7, 2)) oHatchGroup.Children.Add(mp_GPoint(7, 0)) oHatchGroup.Children.Add(mp_GPoint(7, 1)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_TRELLIS Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GLine(0, 0, 3, 0)) oHatchGroup.Children.Add(mp_GLine(1, 1, 2, 1)) oHatchGroup.Children.Add(mp_GLine(0, 2, 3, 2)) oHatchGroup.Children.Add(mp_GPoint(0, 3)) oHatchGroup.Children.Add(mp_GPoint(3, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_SPHERE Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GLine(1, 0, 3, 0)) oHatchGroup.Children.Add(mp_GLine(1, 1, 3, 1)) oHatchGroup.Children.Add(mp_GPoint(0, 2)) oHatchGroup.Children.Add(mp_GPoint(4, 2)) oHatchGroup.Children.Add(mp_GLine(1, 3, 2, 3)) oHatchGroup.Children.Add(mp_GPoint(0, 6)) oHatchGroup.Children.Add(mp_GPoint(4, 6)) oHatchGroup.Children.Add(mp_GLine(1, 7, 3, 7)) oHatchGroup.Children.Add(mp_GLine(5, 7, 6, 7)) oHatchGroup.Children.Add(mp_GLine(5, 3, 7, 3)) oHatchGroup.Children.Add(mp_GLine(5, 4, 7, 4)) oHatchGroup.Children.Add(mp_GLine(5, 5, 7, 5)) oHatchCtrlGroup.Children.Add(mp_GPoint(7, 7)) InvertColors(clrForeColor, clrBackColor) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_SMALLGRID Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GLine(0, 0, 3, 0)) oHatchGroup.Children.Add(mp_GLine(0, 0, 0, 3)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_SMALLCHECKERBOARD Width = 4 Height = 4 oHatchGroup.Children.Add(mp_GRect(0, 0, 2, 2)) oHatchGroup.Children.Add(mp_GRect(2, 2, 2, 2)) yType = T_HATCHTYPE.HT_RECTANGLE Case GRE_HATCHSTYLE.HS_LARGECHECKERBOARD Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GRect(0, 0, 4, 4)) oHatchGroup.Children.Add(mp_GRect(4, 4, 4, 4)) yType = T_HATCHTYPE.HT_RECTANGLE Case GRE_HATCHSTYLE.HS_OUTLINEDDIAMOND Width = 8 Height = 8 oHatchGroup.Children.Add(mp_GPoint(0, 4)) oHatchGroup.Children.Add(mp_GPoint(1, 3)) oHatchGroup.Children.Add(mp_GPoint(2, 2)) oHatchGroup.Children.Add(mp_GPoint(3, 1)) oHatchGroup.Children.Add(mp_GPoint(4, 0)) oHatchGroup.Children.Add(mp_GPoint(5, 1)) oHatchGroup.Children.Add(mp_GPoint(6, 2)) oHatchGroup.Children.Add(mp_GPoint(7, 3)) oHatchGroup.Children.Add(mp_GPoint(7, 5)) oHatchGroup.Children.Add(mp_GPoint(6, 6)) oHatchGroup.Children.Add(mp_GPoint(5, 7)) oHatchGroup.Children.Add(mp_GPoint(3, 7)) oHatchGroup.Children.Add(mp_GPoint(2, 6)) oHatchGroup.Children.Add(mp_GPoint(1, 5)) yType = T_HATCHTYPE.HT_LINE Case GRE_HATCHSTYLE.HS_SOLIDDIAMOND Width = 7 Height = 7 oHatchGroup.Children.Add(mp_GRect(1, 1, 5, 5)) oHatchGroup.Transform = New RotateTransform(45, 3, 3) yType = T_HATCHTYPE.HT_RECTANGLE End Select Dim oBackgroundSquare As New GeometryDrawing(New SolidColorBrush(clrBackColor), Nothing, New RectangleGeometry(New Rect(0, 0, Width, Height))) Dim oHatchBrush As New SolidColorBrush(clrForeColor) Dim oHatchPen As New Pen(oHatchBrush, 1) oHatchBrush.Freeze() oHatchPen.Freeze() Dim oHatchCtrlBrush As New SolidColorBrush(Colors.Red) Dim oHatchCtrlPen As New Pen(oHatchCtrlBrush, 1) oHatchCtrlBrush.Freeze() oHatchCtrlPen.Freeze() Dim oHatch As GeometryDrawing = Nothing Dim oHatchCtrl As GeometryDrawing = Nothing Select Case yType Case T_HATCHTYPE.HT_RECTANGLE oHatch = New GeometryDrawing(oHatchBrush, Nothing, oHatchGroup) If oHatchCtrlGroup.Children.Count > 0 Then oHatchCtrl = New GeometryDrawing(oHatchCtrlBrush, Nothing, oHatchCtrlGroup) End If Case T_HATCHTYPE.HT_LINE oHatch = New GeometryDrawing(Nothing, oHatchPen, oHatchGroup) If oHatchCtrlGroup.Children.Count > 0 Then oHatchCtrl = New GeometryDrawing(Nothing, oHatchCtrlPen, oHatchCtrlGroup) End If End Select Dim oDrawingGroup As New DrawingGroup If bAliased = True Then oDrawingGroup.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased) End If If Not oHatchCtrl Is Nothing Then oDrawingGroup.Children.Add(oHatchCtrl) End If oDrawingGroup.Children.Add(oBackgroundSquare) oDrawingGroup.Children.Add(oHatch) oReturnBrush.Drawing = oDrawingGroup oReturnBrush.Stretch = Stretch.None oReturnBrush.ViewportUnits = BrushMappingMode.Absolute oReturnBrush.Viewport = New Rect(0, 0, Width, Height) oReturnBrush.TileMode = TileMode.Tile oReturnBrush.Freeze() Return oReturnBrush End Function Private Function mp_GLine(ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As LineGeometry If X1 <> X2 Then X2 = X2 + 1 End If If Y1 <> Y2 Then Y2 = Y2 + 1 End If Dim oReturn As New LineGeometry(New Point(X1, Y1), New Point(X2, Y2)) Return oReturn End Function Private Function mp_GPoint(ByVal X1 As Integer, ByVal Y1 As Integer) As LineGeometry Dim oReturn As New LineGeometry(New Point(X1, Y1), New Point(X1 + 1, Y1 + 1)) Return oReturn End Function Private Function mp_GRect(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer) As RectangleGeometry Dim oReturn As New RectangleGeometry(New Rect(X, Y, Width, Height)) Return oReturn End Function Private Sub InvertColors(ByRef clrForeColor As Color, ByRef clrBackColor As Color) Dim clrBuff As Color clrBuff = clrBackColor clrBackColor = clrForeColor clrForeColor = clrBuff End Sub End Class