HatchStyles.vb
C# VB
'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.IOImports System.DrawingImports System.Collections.GenericImports System.LinqImports System.NumericsImports GrapeCity.Documents.DrawingImports GrapeCity.Documents.TextImports GrapeCity.Documents.ImagingImports GCTEXT = GrapeCity.Documents.Text
'' This sample demonstrates the different hatch brush styles.'' Many of those styles implement MS Excel pattern styles.Public Class HatchStyles Function GenerateImage( ByVal pixelSize As Size, ByVal dpi As Single, ByVal opaque As Boolean, Optional ByVal sampleParams As String() = Nothing) As GcBitmap
'' HatchStyle Dim htchStyles = [Enum].GetValues(GetType(HatchStyle)) Dim COLS = 4 Dim w = pixelSize.Width / COLS Dim h = pixelSize.Height / ((htchStyles.Length + COLS - 1) / COLS)
Dim tf = New TextFormat With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSerif.ttf")), .FontSize = 12 }
Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, True, dpi, dpi) Using g = bmp.CreateGraphics(Color.White) Dim row = 0, col = 0 For Each hs As HatchStyle In htchStyles '' Hatch: Dim rc = New RectangleF(col * w, row * h, w, h) Dim b = New HatchBrush(hs) With { .ForeColor = Color.Black, .BackColor = Color.White } g.FillRectangle(rc, b) '' Caption: Dim cap = hs.ToString() Dim scap = g.MeasureString(cap, tf) Dim rcap = New RectangleF( rc.X + (rc.Width - scap.Width) / 2, rc.Y + (rc.Height - scap.Height) / 2, scap.Width, scap.Height) rcap.Inflate(3, 2) g.FillRectangle(rcap, Color.White) g.DrawString(cap, tf, rcap, TextAlignment.Center, ParagraphAlignment.Center) '' Move on col += 1 If col >= COLS Then col = 0 row += 1 End If Next End Using Return bmp End FunctionEnd Class