Applies to: Nevron Diagram for .NET
How to create diagram table shape with dashed borer and solid inner cell borders?
Let's say that you want to create the following table shape with dashed outline border and solid cell borders:
To create this table shape, you can use the following piece of code:
[C#]
private
void
CreateTableShape()
{
NDrawingDocument document = m_View.Document;
m_View.GlobalVisibility.ShowPorts =
false
;
m_View.Grid.Visible =
false
;
const
int
rowCount = 3;
const
int
colCount = 3;
// Create a style sheet for cells borders
NStyleSheet cellsStyleSheet =
new
NStyleSheet(
"CellsStyleSheet"
);
NStyle.SetStrokeStyle(cellsStyleSheet,
new
NStrokeStyle(1, Color.Red));
document.StyleSheets.AddChild(cellsStyleSheet);
// Create and style a table shape
NTableShape tableShape =
new
NTableShape();
tableShape.ShowGrid =
false
;
tableShape.CellPadding =
new
Nevron.Diagram.NMargins(5, 5, 10, 10);
NStyle.SetStrokeStyle(tableShape,
new
NStrokeStyle(1, Color.Black, LinePattern.Dash));
// Add the shape to the document's active layer
document.ActiveLayer.AddChild(tableShape);
// Init the table shape and begin updating its cells
tableShape.InitTable(colCount, rowCount);
tableShape.BeginUpdate();
// Loop through the cells to set their cells and border
int
z = 1;
for
(
int
i = 0; i < rowCount; i++)
{
TableCellBorder cellBorders = i > 0 ? TableCellBorder.Top : TableCellBorder.None;
for
(
int
j = 0; j < colCount; j++)
{
NTableCell cell = tableShape[j, i];
cell.Text =
"Cell "
+ z.ToString();
cell.StyleSheetName = cellsStyleSheet.Name;
cell.Borders = j > 0 ? cellBorders | TableCellBorder.Left : cellBorders;
z++;
}
}
// End the table shape update and set its lacation
tableShape.EndUpdate();
tableShape.Location =
new
NPointF(100, 100);
}
[VB.NET]
Private
Sub
CreateTableShape()
Dim
document
As
NDrawingDocument = m_View.Document
m_View.GlobalVisibility.ShowPorts =
False
m_View.Grid.Visible =
False
Const
rowCount
As
Integer
= 3
Const
colCount
As
Integer
= 3
' Create a style sheet for cells borders
Dim
cellsStyleSheet
As
New
NStyleSheet(
"CellsStyleSheet"
)
NStyle.SetStrokeStyle(cellsStyleSheet,
New
NStrokeStyle(1, Color.Red))
document.StyleSheets.AddChild(cellsStyleSheet)
' Create and style a table shape
Dim
tableShape
As
New
NTableShape()
tableShape.ShowGrid =
False
tableShape.CellPadding =
New
Nevron.Diagram.NMargins(5, 5, 10, 10)
NStyle.SetStrokeStyle(tableShape,
New
NStrokeStyle(1, Color.Black, LinePattern.Dash))
' Add the shape to the document's active layer
document.ActiveLayer.AddChild(tableShape)
' Init the table shape and begin updating its cells
tableShape.InitTable(colCount, rowCount)
tableShape.BeginUpdate()
' Loop through the cells to set their cells and border
Dim
z
As
Integer
= 1
For
i
As
Integer
= 0
To
rowCount - 1
Dim
cellBorders
As
TableCellBorder =
If
(i > 0, TableCellBorder.Top, TableCellBorder.None)
For
j
As
Integer
= 0
To
colCount - 1
Dim
cell
As
NTableCell = tableShape(j, i)
cell.Text =
"Cell "
+ z.ToString()
cell.StyleSheetName = cellsStyleSheet.Name
cell.Borders =
If
(j > 0, cellBorders
Or
TableCellBorder.Left, cellBorders)
z += 1
Next
Next
' End the table shape update and set its lacation
tableShape.EndUpdate()
tableShape.Location =
New
NPointF(100, 100)
End
Sub
Article ID: 224, Created On: 8/6/2012, Modified: 8/6/2012