''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.Drawing
Imports System.IO
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging
Imports GrapeCity.Documents.Layout
Imports GrapeCity.Documents.Layout.Composition
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' This example shows how to draw a simple empty table,
'' using the GrapeCity.Documents.Layout.Composition.Surface and
'' GrapeCity.Documents.Drawing.TableRenderer classes.
'' This example highlights the main elements of the table layout
'' that can be created using the TableRenderer class.
Public Class EmptyTable
Public Function GenerateImage(
ByVal pixelSize As Size,
ByVal dpi As Single,
ByVal opaque As Boolean,
Optional ByVal sampleParams As String() = Nothing) As GcBitmap
Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
Using g = bmp.CreateGraphics(Color.White)
DrawTable(g, pixelSize.Width, pixelSize.Height)
End Using
Return bmp
End Function
Private Shared ReadOnly FormatDesc As TextFormat = New TextFormat() With
{
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")),
.FontSize = 24,
.FontSizeInGraphicUnits = True,
.ForeColor = Color.White
}
Private Shared Sub DrawTable(g As GcGraphics, pageWidth As Single, pageHeight As Single)
Dim surf = New Surface()
Dim view = surf.CreateView(pageWidth, pageHeight)
'' Fill the page with Gray color.
view.CreateVisual(Sub(gr As GcGraphics, vis As Visual)
gr.FillRectangle(vis.AsRectF(), Color.Gray)
End Sub).LayoutRect.AnchorExact(Nothing)
Dim vTable = view.CreateVisual()
Dim tableRect = vTable.LayoutRect
tableRect.AnchorTopLeftRight(Nothing, 36, 36, 36)
'' The paddingAll parameter adds padding to the table grid relative to the table rectangle.
Dim ta = New TableRenderer(g,
tableRect, FixedTableSides.TopLeftRight,
rowCount:=3,
columnCount:=3,
gridLineColor:=Color.Yellow,
gridLineWidth:=5,
rowMinHeight:=100,
paddingAll:=40)
Dim columns = ta.ColumnRects
columns(0).SetStarWidth(1)
columns(1).SetWidth(100)
columns(2).SetStarWidth(3)
ta.TableFrameStyle = New FrameStyle() With
{
.LinePaddingAll = 20,
.LineColor = Color.SlateBlue,
.FillColor = Color.LightGreen,
.LineWidth = 10F
}
ta.ApplyCellConstraints()
vTable.Draw = Sub(gr As GcGraphics, vis As Visual)
Dim rc = vis.AsRectF()
gr.FillRectangle(rc, Color.White)
Dim tl = gr.CreateTextLayout()
tl.AppendLine("Table rectangle (tableRect) is White,", FormatDesc)
tl.AppendLine("Padding of the table frame is 20 (TableFrameStyle.LinePaddingAll),", FormatDesc)
tl.AppendLine("Frame line width is 10 (TableFrameStyle.LineWidth),", FormatDesc)
tl.AppendLine("Frame line color is SlateBlue (TableFrameStyle.LineColor),", FormatDesc)
tl.AppendLine("Frame area color is LightGreen (TableFrameStyle.FillColor),", FormatDesc)
tl.AppendLine("Padding of the table grid is 40 (the paddingAll parameter),", FormatDesc)
tl.AppendLine("Table grid line width is 5 (the gridLineWidth parameter),", FormatDesc)
tl.AppendLine("Grid line color is Yellow (the gridLineColor parameter).", FormatDesc)
gr.DrawTextLayout(tl, New PointF(0, rc.Bottom + 10))
gr.Transform = vis.Layer.Surface.BaseTransform
ta.Render()
End Sub
surf.Render(g)
End Sub
End Class