TableRoundBorders.cs
// // This code is part of Document Solutions for Imaging demos. // Copyright (c) MESCIUS inc. All rights reserved. // using System; using System.IO; using System.Drawing; using System.Numerics; using GrapeCity.Documents.Drawing; using GrapeCity.Documents.Text; using GrapeCity.Documents.Imaging; using GrapeCity.Documents.Layout; using GCTEXT = GrapeCity.Documents.Text; using GCDRAW = GrapeCity.Documents.Drawing; namespace DsImagingWeb.Demos { // 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 GcBitmap GenerateImage(Size pixelSize, float dpi, bool opaque, string[] sampleParams = null) { var bmp = new GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi); using var g = bmp.CreateGraphics(Color.White); DrawTable(g, pixelSize.Width, pixelSize.Height); return bmp; } static void DrawTable(GcGraphics g, float pageWidth, float pageHeight) { var host = new LayoutHost(); var view = host.CreateView(pageWidth, pageHeight); var rt = view.CreateRect(); rt.AnchorTopLeftRight(null, 36, 36, 36); var ta = new TableRenderer(g, rt, FixedTableSides.TopLeftRight, rowCount: 5, columnCount: 4, gridLineColor: Color.Transparent, gridLineWidth: 1, rowMinHeight: 30, paddingAll: 3) { TableFrameStyle = new FrameStyle { FillColor = Color.AliceBlue, LineColor = Color.CornflowerBlue, LineWidth = 1, CornerRadius = 5 } }; var columns = ta.ColumnRects; columns[0].SetStarWidth(1); columns[1].SetStarWidth(5); columns[2].SetStarWidth(2); columns[3].SetStarWidth(3); var fmt = new TextFormat { Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "FreeSans.ttf")), ForeColor = Color.CornflowerBlue, FontSize = 16, FontSizeInGraphicUnits = true }; var csNormal = new CellStyle { TextFormat = fmt, ParagraphAlignment = ParagraphAlignment.Center, PaddingLeftRight = 10, FillColor = Color.MistyRose, LineColor = Color.CornflowerBlue, LinePaddingAll = 2, LineWidth = 1, CornerRadius = 5 }; var csCenter = new CellStyle(csNormal) { TextAlignment = TextAlignment.Center, PaddingLeftRight = 0, }; var csHeader = new CellStyle(csCenter) { TextFormat = new TextFormat(fmt) { 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(); } } }