''
'' 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 GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
'' This example shows how to draw a table representing a time chart,
'' using the GrapeCity.Documents.Drawing.TableRenderer and related classes.
Public Class TimeChartTable
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 Sub DrawTable(g As GcGraphics, pageWidth As Single, pageHeight As Single)
Dim host = New LayoutHost()
Dim view = host.CreateView(pageWidth, pageHeight * 0.7F)
Dim rt = view.CreateRect()
'' Pad the table rectangle equally from left, right, top and bottom:
rt.AnchorDeflate(Nothing, 10)
'' All sides of the table are fixed, so we can apply
'' star widths to columns and star heights to rows:
Dim ta = New TableRenderer(g,
rt, FixedTableSides.All,
rowCount:=10, columnCount:=32,
gridLineColor:=Color.DimGray,
gridLineWidth:=1)
Dim columns = ta.ColumnRects
columns(0).SetWidth(120)
For i = 1 To 31
columns(i).SetStarWidth(1F)
Next
'' Table header is a part of the table;
'' the first row (rows[0]) is for the table header:
Dim rows = ta.RowRects
rows(0).SetHeight(40)
rows(1).SetHeight(30)
For i = 2 To 9
rows(i).SetStarHeight(1F)
Next
Dim fmt = New TextFormat() With
{
.Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")),
.FontSize = 16,
.FontSizeInGraphicUnits = True
}
Dim cs = New CellStyle() With
{
.TextFormat = fmt,
.TextAlignment = TextAlignment.Center
}
Dim csTitle = New CellStyle(cs) With
{
.Background = True,
.TextFormat = New TextFormat(fmt) With
{
.FontSize = 16,
.FontBold = True
}
}
ta.AddCell(csTitle, 0, 0, 1, 32, "Small Business Marketing Plan")
ta.DefaultCellStyle = New CellStyle(cs) With
{
.ParagraphAlignment = ParagraphAlignment.Center
}
For i = 1 To 31
ta.AddCell(1, i, i.ToString())
Next
ta.DefaultCellStyle = New CellStyle(cs) With
{
.TextAlignment = TextAlignment.Leading,
.PaddingLeft = 3
}
ta.AddCell(2, 0, "Business Overview")
ta.AddCell(3, 0, "Market Analysis")
ta.AddCell(4, 0, "Marketing Strategy")
ta.AddCell(5, 0, "Operations Plan")
ta.AddCell(6, 0, "Organization")
ta.AddCell(7, 0, "Management")
ta.AddCell(8, 0, "Legal aspects")
ta.AddCell(9, 0, "Financial Plan")
'' Add merged background cells for color highlighting:
AddBand(ta, 2, 1, 6, Color.FromArgb(247, 202, 171))
AddBand(ta, 3, 2, 7, Color.FromArgb(179, 198, 231))
AddBand(ta, 4, 5, 6, Color.FromArgb(255, 229, 154))
AddBand(ta, 5, 11, 6, Color.FromArgb(45, 116, 182))
AddBand(ta, 6, 17, 6, Color.FromArgb(255, 155, 155))
AddBand(ta, 7, 18, 6, Color.FromArgb(197, 224, 179))
AddBand(ta, 8, 24, 4, Color.FromArgb(3, 174, 80))
AddBand(ta, 9, 28, 4, Color.FromArgb(1, 176, 241))
'' We exclude the first row when we add missing cells
'' to avoid drawing grid lines for the table header:
ta.AddMissingCells(1, 0, 9, 32)
ta.Render()
End Sub
'' The band has the background cell style. So, it is displayed behind the table grid.
Private Shared Sub AddBand(ta As TableRenderer, rowIndex As Integer, columnIndex As Integer, columnCount As Integer, color As Color)
ta.AddCell(New CellStyle() With
{
.Background = True,
.FillColor = color
}, rowIndex, columnIndex, 1, columnCount)
End Sub
End Class