Annotation Shapes Example for WinForms

Nevron NOV Diagram for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms Diagram examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Annotation Shapes Example for WinForms Description

This example shows the annotation shapes created by the NAnnotationShapeFactory.


Annotation Shapes Example

C# Annotation Shapes Example Code for Nevron Diagram for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.Expressions;
using Nevron.Nov.Diagram.Shapes;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
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 - NAnnotationShapesExample";

			// 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();
            drawingViewWithRibbon.GetRibbon().Tab.Expanded = false;
			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 @"

This example shows the annotation shapes created by the NAnnotationShapeFactory.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Predefined Libraries", "https://www.nevron.com/docs/openvision/diagram-predefined-libraries.html"), ("Libraries", "https://www.nevron.com/docs/openvision/diagram-libraries.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Library Browser", "https://www.nevron.com/docs/openvision/diagram-library-browser.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { NDrawing drawing = drawingDocument.Content; NPage activePage = drawing.ActivePage; activePage.ZoomMode = ENZoomMode.Fit; // Hide grid and ports drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; // Create all shapes from the factory NAnnotationShapeFactory factory = new NAnnotationShapeFactory(60, 60); bool is1D = false; int row = 0, col = 0; double cellWidth = 0; double cellHeight = 260; for (int i = 0; i < factory.ShapeCount; i++, col++) { NShape shape = factory.CreateShape(i); NShape tempShape; shape.HorizontalPlacement = ENHorizontalPlacement.Center; shape.VerticalPlacement = ENVerticalPlacement.Center; if (i == (int)ENAnnotationShape.Text || i == (int)ENAnnotationShape.FiveRuledColumn || i == (int)ENAnnotationShape.InfoLine || i == (int)ENAnnotationShape.NorthArrow5 || i == (int)ENAnnotationShape.NoteSymbol || i == (int)ENAnnotationShape.ReferenceTriangle || i == (int)ENAnnotationShape.ReferenceRectangle || i == (int)ENAnnotationShape.ReferenceHexagon || i == (int)ENAnnotationShape.ReferenceCircle || i == (int)ENAnnotationShape.ReferenceOval) { NGroup group = new NGroup(); group.Width = shape.Width; group.Height = shape.Height; if (i == (int)ENAnnotationShape.Text) { shape.PinX = 0; shape.SetFx(NShape.PinYProperty, "Height"); } else { shape.SetFx(NShape.PinXProperty, "Width / 2"); shape.SetFx(NShape.PinYProperty, "Height / 2"); } group.TextBlock = new NTextBlock(shape.Name); shape.SetFx(NShape.WidthProperty, "$ParentSheet.Width"); shape.SetFx(NShape.HeightProperty, "$ParentSheet.Height"); MoveTextBelowShape(group); group.Shapes.Add(shape); activePage.Items.Add(group); tempShape = group; } else { if (i != (int)ENAnnotationShape.Benchmark) { shape.Text = shape.Name; MoveTextBelowShape(shape); if (i == (int)ENAnnotationShape.ReferenceCallout1) { shape.TextBlock.PinX = 40; shape.TextBlock.PinY = 10; } if (i == (int)ENAnnotationShape.ReferenceCallout2) { shape.TextBlock.Angle = new NAngle(0); shape.TextBlock.PinY = 100; } } activePage.Items.Add(shape); tempShape = shape; } if (col >= 5) { row++; col = 0; cellWidth = 0; is1D = false; } int widthGap = is1D ? 150 : 100; is1D = shape.ShapeType == ENShapeType.Shape1D; NPoint beginPoint = new NPoint(widthGap + cellWidth, 50 + row * cellHeight); if (is1D) { NPoint endPoint = beginPoint + new NPoint(0, cellHeight - 60); if (i == (int)ENAnnotationShape.ReferenceCallout1 || i == (int)ENAnnotationShape.ReferenceCallout2) { tempShape.SetBeginPoint(beginPoint); tempShape.SetEndPoint(endPoint); } else { tempShape.SetBeginPoint(endPoint); tempShape.SetEndPoint(beginPoint); } } else { tempShape.SetBounds(beginPoint.X, beginPoint.Y, shape.Width, shape.Height); } cellWidth += widthGap + tempShape.Width; } // size page to content activePage.Layout.ContentPadding = new NMargins(40); activePage.SizeToContent(); } private void MoveTextBelowShape(NShape shape) { if (shape.ShapeType == ENShapeType.Shape2D) { shape.MoveTextBlockBelowShape(); return; } // if the shape is 1D put the text block on the left part of the shape and rotate it on 90 degrees. NTextBlock textBlock = shape.GetTextBlock(); textBlock.Padding = new NMargins(5, 0, 0, 0); textBlock.ResizeMode = ENTextBlockResizeMode.TextSize; textBlock.PinX = shape.BeginX; textBlock.SetFx(NTextBlock.PinYProperty, new NShapeHeightFactorFx(0)); textBlock.LocPinY = 0; textBlock.Angle = new NAngle(90); } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NDrawingView m_DrawingView; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Annotation Shapes Example for WinForms Solution

VB.NET Annotation Shapes Example Code for Nevron Diagram for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.Expressions
Imports Nevron.Nov.Diagram.Shapes
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
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 - NAnnotationShapesExample"

        ' 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()
            drawingViewWithRibbon.GetRibbon().Tab.Expanded = False
            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 "

This example shows the annotation shapes created by the NAnnotationShapeFactory.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Predefined Libraries", "https://www.nevron.com/docs/openvision/diagram-predefined-libraries.html"), ("Libraries", "https://www.nevron.com/docs/openvision/diagram-libraries.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Library Browser", "https://www.nevron.com/docs/openvision/diagram-library-browser.html")} End Function Private Sub InitDiagram(drawingDocument As NDrawingDocument) Dim drawing = drawingDocument.Content Dim activePage = drawing.ActivePage activePage.ZoomMode = ENZoomMode.Fit ' Hide grid and ports drawing.ScreenVisibility.ShowGrid = False drawing.ScreenVisibility.ShowPorts = False ' Create all shapes from the factory Dim factory As NAnnotationShapeFactory = New NAnnotationShapeFactory(60, 60) Dim is1D = False Dim row = 0, col = 0 Dim cellWidth As Double = 0 Dim cellHeight As Double = 260 Dim i = 0 While i < factory.ShapeCount Dim shape = factory.CreateShape(i) Dim tempShape As NShape shape.HorizontalPlacement = ENHorizontalPlacement.Center shape.VerticalPlacement = ENVerticalPlacement.Center If i = CInt(ENAnnotationShape.Text) OrElse i = CInt(ENAnnotationShape.FiveRuledColumn) OrElse i = CInt(ENAnnotationShape.InfoLine) OrElse i = CInt(ENAnnotationShape.NorthArrow5) OrElse i = CInt(ENAnnotationShape.NoteSymbol) OrElse i = CInt(ENAnnotationShape.ReferenceTriangle) OrElse i = CInt(ENAnnotationShape.ReferenceRectangle) OrElse i = CInt(ENAnnotationShape.ReferenceHexagon) OrElse i = CInt(ENAnnotationShape.ReferenceCircle) OrElse i = CInt(ENAnnotationShape.ReferenceOval) Then Dim group As NGroup = New NGroup() group.Width = shape.Width group.Height = shape.Height If i = CInt(ENAnnotationShape.Text) Then shape.PinX = 0 shape.SetFx(NShape.PinYProperty, "Height") Else shape.SetFx(NShape.PinXProperty, "Width / 2") shape.SetFx(NShape.PinYProperty, "Height / 2") End If group.TextBlock = New NTextBlock(shape.Name) shape.SetFx(NShape.WidthProperty, "$ParentSheet.Width") shape.SetFx(NShape.HeightProperty, "$ParentSheet.Height") MoveTextBelowShape(group) group.Shapes.Add(shape) activePage.Items.Add(group) tempShape = group Else If i <> CInt(ENAnnotationShape.Benchmark) Then shape.Text = shape.Name MoveTextBelowShape(shape) If i = CInt(ENAnnotationShape.ReferenceCallout1) Then shape.TextBlock.PinX = 40 shape.TextBlock.PinY = 10 End If If i = CInt(ENAnnotationShape.ReferenceCallout2) Then shape.TextBlock.Angle = New NAngle(0) shape.TextBlock.PinY = 100 End If End If activePage.Items.Add(shape) tempShape = shape End If If col >= 5 Then row += 1 col = 0 cellWidth = 0 is1D = False End If Dim widthGap = If(is1D, 150, 100) is1D = shape.ShapeType Is ENShapeType.Shape1D Dim beginPoint As NPoint = New NPoint(widthGap + cellWidth, 50 + row * cellHeight) If is1D Then Dim endPoint As NPoint = beginPoint + New NPoint(0, cellHeight - 60) If i = CInt(ENAnnotationShape.ReferenceCallout1) OrElse i = CInt(ENAnnotationShape.ReferenceCallout2) Then tempShape.SetBeginPoint(beginPoint) tempShape.SetEndPoint(endPoint) Else tempShape.SetBeginPoint(endPoint) tempShape.SetEndPoint(beginPoint) End If Else tempShape.SetBounds(beginPoint.X, beginPoint.Y, shape.Width, shape.Height) End If cellWidth += widthGap + tempShape.Width i += 1 col += 1 End While ' size page to content activePage.Layout.ContentPadding = New NMargins(40) activePage.SizeToContent() End Sub Private Sub MoveTextBelowShape(shape As NShape) If shape.ShapeType Is ENShapeType.Shape2D Then shape.MoveTextBlockBelowShape() Return End If ' if the shape is 1D put the text block on the left part of the shape and rotate it on 90 degrees. Dim textBlock As NTextBlock = shape.GetTextBlock() textBlock.Padding = New NMargins(5, 0, 0, 0) textBlock.ResizeMode = ENTextBlockResizeMode.TextSize textBlock.PinX = shape.BeginX textBlock.SetFx(NShapeBlock.PinYProperty, New NShapeHeightFactorFx(0)) textBlock.LocPinY = 0 textBlock.Angle = New NAngle(90) End Sub #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

Download a fully functional VB.NET (.vb) Annotation Shapes Example for WinForms Solution