开始使用Reports for WinForms > 打印和预览功能入门 > 制作一个简单的表格 > 创建一个三行三列的表格 |
本文演示了设置一个三行三列表格的基本内容。完成如下步骤:
这样就能使C1PrintPreviewControl控件显示C1PrintDocument了
Visual Basic
Visual Basic 拷贝代码Dim table As C1.C1Preview.RenderTable = New C1.C1Preview.RenderTable(Me.C1PrintDocument1)
C#
C# 拷贝代码C1.C1Preview.RenderTable table = new C1.C1Preview.RenderTable(this.c1PrintDocument1);
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
' Add 3 rows. Dim r As Integer = 3 ' Add 3 columns. Dim c As Integer = 3 Dim row As Integer Dim col As Integer For row = 0 To r - 1 Step +1 For col = 0 To c - 1 Step +1 Dim celltext As C1.C1Preview.RenderText = New C1.C1Preview.RenderText(Me.C1PrintDocument1) ' Add empty cells. celltext.Text = String.Format("", row, col) table.Cells(row, col).RenderObject = celltext Next Next |
C#
C# |
拷贝代码
|
---|---|
// Add 3 rows. const int r = 3; // Add 3 columns. const int c = 3; for (int row = 0; row < r; ++row) { for (int col = 0; col < c; ++col) { C1.C1Preview.RenderText celltext = new C1.C1Preview.RenderText(this.c1PrintDocument1); celltext.Text = string.Format("", row, col); // Add empty cells. table.Cells[row, col].RenderObject = celltext; } } |
此外注意,当我们直接将列添加到表格时,行也被添加到了表格主体(Body)中。这是因为RenderTable 对象总是由三个区域组成:头部(Header),主体(Body)和尾部(Footer)。在表格中这三者都是有可能为空的。如果你只是想创建一个简单的表格,那么你可以像我们这个例子中的做法一样,直接将行添加到主体(Body)中即可。
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
table.Height = New C1.C1Preview.Unit(15, C1.C1Preview.UnitTypeEnum.Cm) table.Width = New C1.C1Preview.Unit(15, C1.C1Preview.UnitTypeEnum.Cm) |
C#
C# |
拷贝代码
|
---|---|
table.Height = new C1.C1Preview.Unit(15, C1.C1Preview.UnitTypeEnum.Cm); table.Width = new C1.C1Preview.Unit(15, C1.C1Preview.UnitTypeEnum.Cm); |
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
table.Style.GridLines.All = New C1.C1Preview.LineDef(Color.DarkGray) |
C#
C# |
拷贝代码
|
---|---|
table.Style.GridLines.All = new C1.C1Preview.LineDef(Color.DarkGray); |
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Me.C1PrintDocument1.Body.Children.Add(table) Me.C1PrintDocument1.Generate() |
C#
C# |
拷贝代码
|
---|---|
this.c1PrintDocument1.Body.Children.Add(table); this.c1PrintDocument1.Generate(); |
你的应用程序运行时将会看起来跟下图很相似: