The example demonstrates how to connect table ports to other shapes.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NTablePortsExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// Create a simple drawing
NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
m_DrawingView = drawingViewWithRibbon.View;
m_DrawingView.Document.HistoryService.Pause();
try
{
InitDiagram(m_DrawingView.Document);
}
finally
{
m_DrawingView.Document.HistoryService.Resume();
}
return drawingViewWithRibbon;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"The example demonstrates how to connect table ports to other shapes.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Ports", "https://www.nevron.com/docs/openvision/diagram-ports.html"),
("Snap and Glue", "https://www.nevron.com/docs/openvision/diagram-snap-and-glue.html"),
("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"),
("Routable Connectors", "https://www.nevron.com/docs/openvision/diagram-routable-connectors.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
NDrawing drawing = drawingDocument.Content;
NPage activePage = drawing.ActivePage;
// hide the grid
drawing.ScreenVisibility.ShowGrid = false;
string[] tableDescription = new string[] { "Table With Column Ports", "Table With Row Ports", "Table With Cell Ports", "Table With Grid Ports" };
ENPortsDistributionMode[] tablePortDistributionModes = new ENPortsDistributionMode[] { ENPortsDistributionMode.ColumnsOnly, ENPortsDistributionMode.RowsOnly, ENPortsDistributionMode.CellBased, ENPortsDistributionMode.GridBased };
NTableBlock[] tableBlocks = new NTableBlock[tablePortDistributionModes.Length];
double margin = 40;
double tableSize = 200;
double gap = activePage.Width - margin * 2 - tableSize * 2;
double yPos = margin;
int portDistributionModeIndex = 0;
for (int y = 0; y < 2; y++)
{
double xPos = margin;
for (int x = 0; x < 2; x++)
{
NShape shape = new NShape();
shape.SetBounds(new NRectangle(xPos, yPos, tableSize, tableSize));
xPos += tableSize + gap;
// create table
NTableBlock tableBlock = CreateTableBlock(tableDescription[portDistributionModeIndex]);
// collect the block to connect it to the center shape
tableBlocks[portDistributionModeIndex] = tableBlock;
tableBlock.Content.AllowSpacingBetweenCells = false;
tableBlock.ResizeMode = ENTableBlockResizeMode.FitToShape;
tableBlock.PortsDistributionMode = tablePortDistributionModes[portDistributionModeIndex++];
shape.TextBlock = tableBlock;
drawing.ActivePage.Items.AddChild(shape);
}
yPos += tableSize + gap;
}
NShape centerShape = new NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle);
centerShape.Text = "Table Ports allow you to connect tables to other shapes";
centerShape.TextBlock.FontStyleBold = true;
((NTextBlock)centerShape.TextBlock).VerticalAlignment = ENVerticalAlignment.Center;
((NTextBlock)centerShape.TextBlock).HorizontalAlignment = ENAlign.Center;
activePage.Items.AddChild(centerShape);
double center = drawing.ActivePage.Width / 2.0;
double shapeSize = 100;
centerShape.SetBounds(new NRectangle(center - shapeSize / 2.0, center - shapeSize / 2.0, shapeSize, shapeSize));
// get the column port for the first column on the bottom side
NTableColumnPort columnPort;
if (tableBlocks[0].TryGetColumnPort(0, false, out columnPort))
{
Connect(columnPort, centerShape.GetPortByName("Left"));
}
// get the row port for the second row on the left side
NTableRowPort rowPort;
if (tableBlocks[1].TryGetRowPort(1, true, out rowPort))
{
Connect(rowPort, centerShape.GetPortByName("Top"));
}
// get the cell port of the first cell on the top side
NTableCellPort cellPort;
if (tableBlocks[2].TryGetCellPort(0, 0, ENTableCellPortDirection.Top, out cellPort))
{
Connect(cellPort, centerShape.GetPortByName("Bottom"));
}
// get the cell port of the first row on the left side
NTableRowPort rowPort1;
if (tableBlocks[3].TryGetRowPort(0, true, out rowPort1))
{
Connect(rowPort1, centerShape.GetPortByName("Right"));
}
}
private void Connect(NPort beginPort, NPort endPort)
{
NRoutableConnector connector = new NRoutableConnector();
connector.RerouteMode = ENRoutableConnectorRerouteMode.Always;
m_DrawingView.ActivePage.Items.AddChild(connector);
connector.GlueBeginToPort(beginPort);
connector.GlueEndToPort(endPort);
}
private NTableBlock CreateTableBlock(string description)
{
NTableBlock tableBlock = new NTableBlock(4, 3, NBorder.CreateFilledBorder(NColor.Black), new NMargins(1));
NTableBlockContent tableBlockContent = tableBlock.Content;
NTableCell tableCell = tableBlock.Content.Rows[0].Cells[0];
tableCell.ColSpan = int.MaxValue;
tableCell.Blocks.Clear();
NParagraph par = new NParagraph(description);
par.FontStyleBold = true;
tableCell.Blocks.Add(par);
for (int rowIndex = 1; rowIndex < tableBlockContent.Rows.Count; rowIndex++)
{
NTableRow row = tableBlockContent.Rows[rowIndex];
for (int colIndex = 0; colIndex < tableBlockContent.Columns.Count; colIndex++)
{
NTableCell cell = row.Cells[colIndex];
cell.Blocks.Clear();
cell.Blocks.Add(new NParagraph("This is a table cell [" + rowIndex.ToString() + ", " + colIndex.ToString() + "]"));
}
}
// make sure all columns are percentage based
double percent = 100 / tableBlockContent.Columns.Count;
for (int i = 0; i < tableBlockContent.Columns.Count; i++)
{
tableBlockContent.Columns[i].PreferredWidth = new Nevron.Nov.NMultiLength(Nevron.Nov.ENMultiLengthUnit.Percentage, percent);
}
return tableBlock;
}
#endregion
#region Implementation
///
/// Adds rich formatted text to the specified text block content
///
///
private void AddFormattedTextToContent(NTextBlockContent content)
{
content.Blocks.Add(GetTitleParagraph("Bullet lists allow you to apply automatic numbering on paragraphs or groups of blocks.", 1));
// setting bullet list template type
{
content.Blocks.Add(GetTitleParagraph("Following are bullet lists with different formatting", 2));
ENBulletListTemplateType[] values = NEnum.GetValues();
string[] names = NEnum.GetNames();
string itemText = "Bullet List Item";
for (int i = 0; i < values.Length - 1; i++)
{
NGroupBlock group = new NGroupBlock();
content.Blocks.Add(group);
group.MarginTop = 10;
group.MarginBottom = 10;
NBulletList bulletList = new NBulletList(values[i]);
content.BulletLists.Add(bulletList);
for (int j = 0; j < 3; j++)
{
NParagraph paragraph = new NParagraph(itemText + j.ToString());
NBulletInline bullet = new NBulletInline();
bullet.List = bulletList;
paragraph.Bullet = bullet;
group.Blocks.Add(paragraph);
}
}
}
// nested bullet lists
{
content.Blocks.Add(GetTitleParagraph("Following is an example of bullets with different bullet level", 2));
NBulletList bulletList = new NBulletList(ENBulletListTemplateType.Decimal);
content.BulletLists.Add(bulletList);
NGroupBlock group = new NGroupBlock();
content.Blocks.Add(group);
for (int i = 0; i < 3; i++)
{
NParagraph par = new NParagraph("Bullet List Item" + i.ToString(), bulletList, 0);
group.Blocks.Add(par);
for (int j = 0; j < 2; j++)
{
NParagraph nestedPar = new NParagraph("Nested Bullet List Item" + i.ToString(), bulletList, 1);
nestedPar.MarginLeft = 10;
group.Blocks.Add(nestedPar);
}
}
}
}
///
///
///
///
///
///
internal static NParagraph GetTitleParagraphNoBorder(string text, int level)
{
double fontSize = 10;
ENFontStyle fontStyle = ENFontStyle.Regular;
switch (level)
{
case 1:
fontSize = 16;
fontStyle = ENFontStyle.Bold;
break;
case 2:
fontSize = 10;
fontStyle = ENFontStyle.Bold;
break;
}
NParagraph paragraph = new NParagraph();
paragraph.HorizontalAlignment = ENAlign.Left;
paragraph.FontSize = fontSize;
paragraph.FontStyle = fontStyle;
NTextInline textInline = new NTextInline(text);
textInline.FontStyle = fontStyle;
textInline.FontSize = fontSize;
paragraph.Inlines.Add(textInline);
return paragraph;
}
///
/// Gets a paragraph with title formatting
///
///
///
internal static NParagraph GetTitleParagraph(string text, int level)
{
NColor color = NColor.Black;
NParagraph paragraph = GetTitleParagraphNoBorder(text, level);
paragraph.HorizontalAlignment = ENAlign.Left;
paragraph.Border = CreateLeftTagBorder(color);
paragraph.BorderThickness = new NMargins(5.0, 0.0, 0.0, 0.0);
return paragraph;
}
///
/// Creates a left tag border with the specified border
///
///
///
private static NBorder CreateLeftTagBorder(NColor color)
{
NBorder border = new NBorder();
border.LeftSide = new NBorderSide();
border.LeftSide.Fill = new NColorFill(color);
return border;
}
#endregion
#region Event Handlers
#endregion
#region Fields
private NDrawingView m_DrawingView;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.Shapes
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Text
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NTablePortsExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
pairBox.FillMode = ENStackFillMode.First
pairBox.FitMode = ENStackFitMode.First
pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)
' Host the example in the form
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
' Create a simple drawing
Dim drawingViewWithRibbon As NDrawingViewWithRibbon = New NDrawingViewWithRibbon()
m_DrawingView = drawingViewWithRibbon.View
m_DrawingView.Document.HistoryService.Pause()
Try
InitDiagram(m_DrawingView.Document)
Finally
m_DrawingView.Document.HistoryService.Resume()
End Try
Return drawingViewWithRibbon
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "The example demonstrates how to connect table ports to other shapes.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Ports", "https://www.nevron.com/docs/openvision/diagram-ports.html"), ("Snap and Glue", "https://www.nevron.com/docs/openvision/diagram-snap-and-glue.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Routable Connectors", "https://www.nevron.com/docs/openvision/diagram-routable-connectors.html")}
End Function
Private Sub InitDiagram(drawingDocument As NDrawingDocument)
Dim drawing = drawingDocument.Content
Dim activePage = drawing.ActivePage
' hide the grid
drawing.ScreenVisibility.ShowGrid = False
Dim tableDescription = New String() {"Table With Column Ports", "Table With Row Ports", "Table With Cell Ports", "Table With Grid Ports"}
Dim tablePortDistributionModes = New ENPortsDistributionMode() {ENPortsDistributionMode.ColumnsOnly, ENPortsDistributionMode.RowsOnly, ENPortsDistributionMode.CellBased, ENPortsDistributionMode.GridBased}
Dim tableBlocks = New NTableBlock(tablePortDistributionModes.Length - 1) {}
Dim margin As Double = 40
Dim tableSize As Double = 200
Dim gap = activePage.Width - margin * 2 - tableSize * 2
Dim yPos = margin
Dim portDistributionModeIndex = 0
For y = 0 To 1
Dim xPos = margin
For x = 0 To 1
Dim shape As NShape = New NShape()
shape.SetBounds(New NRectangle(xPos, yPos, tableSize, tableSize))
xPos += tableSize + gap
' create table
Dim tableBlock = CreateTableBlock(tableDescription(portDistributionModeIndex))
' collect the block to connect it to the center shape
tableBlocks(portDistributionModeIndex) = tableBlock
tableBlock.Content.AllowSpacingBetweenCells = False
tableBlock.ResizeMode = ENTableBlockResizeMode.FitToShape
tableBlock.PortsDistributionMode = tablePortDistributionModes(Math.Min(System.Threading.Interlocked.Increment(portDistributionModeIndex), portDistributionModeIndex - 1))
shape.TextBlock = tableBlock
drawing.ActivePage.Items.AddChild(shape)
Next
yPos += tableSize + gap
Next
Dim centerShape As NShape = New NBasicShapeFactory().CreateShape(ENBasicShape.Rectangle)
centerShape.Text = "Table Ports allow you to connect tables to other shapes"
centerShape.TextBlock.FontStyleBold = True
CType(centerShape.TextBlock, NTextBlock).VerticalAlignment = ENVerticalAlignment.Center
CType(centerShape.TextBlock, NTextBlock).HorizontalAlignment = ENAlign.Center
activePage.Items.AddChild(centerShape)
Dim center = drawing.ActivePage.Width / 2.0
Dim shapeSize As Double = 100
centerShape.SetBounds(New NRectangle(center - shapeSize / 2.0, center - shapeSize / 2.0, shapeSize, shapeSize))
' get the column port for the first column on the bottom side
Dim columnPort As NTableColumnPort
If tableBlocks(0).TryGetColumnPort(0, False, columnPort) Then
Connect(columnPort, centerShape.GetPortByName("Left"))
End If
' get the row port for the second row on the left side
Dim rowPort As NTableRowPort
If tableBlocks(1).TryGetRowPort(1, True, rowPort) Then
Connect(rowPort, centerShape.GetPortByName("Top"))
End If
' get the cell port of the first cell on the top side
Dim cellPort As NTableCellPort
If tableBlocks(CInt(2)).TryGetCellPort(0, 0, ENTableCellPortDirection.Top, cellPort) Then
Connect(cellPort, centerShape.GetPortByName("Bottom"))
End If
' get the cell port of the first row on the left side
Dim rowPort1 As NTableRowPort
If tableBlocks(3).TryGetRowPort(0, True, rowPort1) Then
Connect(rowPort1, centerShape.GetPortByName("Right"))
End If
End Sub
Private Sub Connect(beginPort As NPort, endPort As NPort)
Dim connector As NRoutableConnector = New NRoutableConnector()
connector.RerouteMode = ENRoutableConnectorRerouteMode.Always
m_DrawingView.ActivePage.Items.AddChild(connector)
connector.GlueBeginToPort(beginPort)
connector.GlueEndToPort(endPort)
End Sub
Private Function CreateTableBlock(description As String) As NTableBlock
Dim tableBlock As NTableBlock = New NTableBlock(4, 3, NBorder.CreateFilledBorder(NColor.Black), New NMargins(1))
Dim tableBlockContent = tableBlock.Content
Dim tableCell = tableBlock.Content.Rows(0).Cells(0)
tableCell.ColSpan = Integer.MaxValue
tableCell.Blocks.Clear()
Dim par As NParagraph = New NParagraph(description)
par.FontStyleBold = True
tableCell.Blocks.Add(par)
For rowIndex = 1 To tableBlockContent.Rows.Count - 1
Dim row = tableBlockContent.Rows(rowIndex)
For colIndex = 0 To tableBlockContent.Columns.Count - 1
Dim cell = row.Cells(colIndex)
cell.Blocks.Clear()
cell.Blocks.Add(New NParagraph("This is a table cell [" & rowIndex.ToString() & ", " & colIndex.ToString() & "]"))
Next
Next
' make sure all columns are percentage based
Dim percent = 100 / tableBlockContent.Columns.Count
For i = 0 To tableBlockContent.Columns.Count - 1
tableBlockContent.Columns(i).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, percent)
Next
Return tableBlock
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_DrawingView As NDrawingView
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class