このトピックは、テーブル内の特定のセルの背景色を作成する方法を示します。また、 CellStyle プロパティを使用して、レンダリングされるテーブルで使用するスタイルを設定する方法も示します。このトピックは、3行3列のテーブルがあることを前提としています。
Visual Basic コードの書き方
| Visual Basic |
コードのコピー
|
|---|---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' テーブルを作成します。
Dim table As C1.C1Preview.RenderTable = New C1.C1Preview.RenderTable(Me.C1PrintDocument1)
table.Style.GridLines.All = New C1.C1Preview.LineDef(Color.DarkGray)
Dim r As Integer = 3
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)
' 空のセルを追加します。
celltext.Text = String.Format("", row, col)
table.Cells(row, col).RenderObject = celltext
Next
Next
' ドキュメントを生成します。
Me.C1PrintDocument1.Body.Children.Add(table)
Me.C1PrintDocument1.Generate()
End Sub
|
|
C# コードの書き方
| C# |
コードのコピー
|
|---|---|
private void Form1_Load(object sender, System.EventArgs e)
{
// テーブルを作成します。
C1.C1Preview.RenderTable table = new C1.C1Preview.RenderTable(this.c1PrintDocument1);
table.Style.GridLines.All = new C1.C1Preview.LineDef(Color.DarkGray);
const int r = 3;
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);
// 空のセルを追加します。
table.Cells[row, col].RenderObject = celltext;
}
}
// ドキュメントを生成します。
this.c1PrintDocument1.Body.Children.Add(table);
this.c1PrintDocument1.Generate();
}
|
|
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.Width = new C1.C1Preview.Unit(15, C1.C1Preview.UnitTypeEnum.Cm); |
|
Visual Basic コードの書き方
| Visual Basic |
コードのコピー
|
|---|---|
table.Cells(1, 2).CellStyle.BackColor = Color.Crimson |
|
C# コードの書き方
| C# |
コードのコピー
|
|---|---|
table.Cells[1, 2].CellStyle.BackColor = Color.Crimson; |
|
Visual Basic コードの書き方
| Visual Basic |
コードのコピー
|
|---|---|
table.Cells(0, 1).CellStyle.BackColor = Color.BlueViolet |
|
C# コードの書き方
| C# |
コードのコピー
|
|---|---|
table.Cells[0, 1].CellStyle.BackColor = Color.BlueViolet; |
|
テーブルは次のように表示されます。
