TableRoundBorders.vb
C# VB
'''' This code is part of Document Solutions for Imaging demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.DrawingImports System.IOImports GrapeCity.Documents.DrawingImports GrapeCity.Documents.TextImports GrapeCity.Documents.ImagingImports GrapeCity.Documents.LayoutImports GCTEXT = GrapeCity.Documents.Text
'' This example shows how to draw a table with rounded'' table and cell borders,'' using the GrapeCity.Documents.Drawing.TableRenderer and related classes.Public Class TableRoundBorders 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)
Dim rt = view.CreateRect() rt.AnchorTopLeftRight(Nothing, 36, 36, 36)
Dim ta = New TableRenderer(g, rt, FixedTableSides.TopLeftRight, rowCount:=5, columnCount:=4, gridLineColor:=Color.Transparent, gridLineWidth:=1, rowMinHeight:=30, paddingAll:=3) With { .TableFrameStyle = New FrameStyle() With { .FillColor = Color.AliceBlue, .LineColor = Color.CornflowerBlue, .LineWidth = 1, .CornerRadius = 5 } }
Dim columns = ta.ColumnRects columns(0).SetStarWidth(1) columns(1).SetStarWidth(5) columns(2).SetStarWidth(2) columns(3).SetStarWidth(3)
Dim fmt = New TextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")), .ForeColor = Color.CornflowerBlue, .FontSize = 16, .FontSizeInGraphicUnits = True } Dim csNormal = New CellStyle() With { .TextFormat = fmt, .ParagraphAlignment = ParagraphAlignment.Center, .PaddingLeftRight = 10, .FillColor = Color.MistyRose, .LineColor = Color.CornflowerBlue, .LinePaddingAll = 2, .LineWidth = 1, .CornerRadius = 5 } Dim csCenter = New CellStyle(csNormal) With { .TextAlignment = TextAlignment.Center, .PaddingLeftRight = 0 } Dim csHeader = New CellStyle(csCenter) With { .TextFormat = New TextFormat(fmt) With { .ForeColor = Color.White, .FontBold = True }, .FillColor = Color.LightBlue }
ta.AddCell(csHeader, 0, 0, "#") ta.AddCell(csHeader, 0, 1, "Name") ta.AddCell(csHeader, 0, 2, "Age") ta.AddCell(csHeader, 0, 3, "Country")
ta.AddCell(csCenter, 1, 0, "1.") ta.AddCell(csNormal, 1, 1, "Alice") ta.AddCell(csCenter, 1, 2, "25") ta.AddCell(csNormal, 1, 3, "Spain")
ta.AddCell(csCenter, 2, 0, "2.") ta.AddCell(csNormal, 2, 1, "Bob") ta.AddCell(csCenter, 2, 2, "36") ta.AddCell(csNormal, 2, 3, "Germany")
ta.AddCell(csCenter, 3, 0, "3.") ta.AddCell(csNormal, 3, 1, "Ken") ta.AddCell(csCenter, 3, 2, "5") ta.AddCell(csNormal, 3, 3, "Brazil")
ta.AddCell(csCenter, 4, 0, "4.") ta.AddCell(csNormal, 4, 1, "Teddy") ta.AddCell(csCenter, 4, 2, "12") ta.AddCell(csNormal, 4, 3, "Mexico")
ta.ApplyCellConstraints()
ta.Render() End SubEnd Class