Geometry Commands 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.

Geometry Commands Example for WinForms Description

Demonstrates the geometry commands that you can use to construct the shapes geometry.

On the first row you can see the different types of geometry commands that you can use to plot geometry. Plotter commands are designed to be placed in a sequence so that you can create arbitrary geometry by combining MoveTo, LineTo, CubicBezierTo, ArcTo, CircularActTo and EllipticalArcTo commands.

On the second row you can see the different types of draw box commands. These commands are used when you want to output more vertices or generally draw more complex clipart shapes with single geometry commands.

The active page is switched to geometry edit mode, so when you select shapes you can see handles you can move to modify the geometry.


Geometry Commands Example

C# Geometry Commands Example Code for Nevron Diagram for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Diagram;
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 - NGeometryCommandsExample";

			// 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);
            }
            finally
            {
                m_DrawingView.Document.HistoryService.Resume();
            }

            return drawingViewWithRibbon;
        }
        public NWidget CreateExampleControls()
        {
            return null;
        }
        public string GetExampleDescription()
        {
            return @"

Demonstrates the geometry commands that you can use to construct the shapes geometry.

On the first row you can see the different types of geometry commands that you can use to plot geometry. Plotter commands are designed to be placed in a sequence so that you can create arbitrary geometry by combining MoveTo, LineTo, CubicBezierTo, ArcTo, CircularActTo and EllipticalArcTo commands.

On the second row you can see the different types of draw box commands. These commands are used when you want to output more vertices or generally draw more complex clipart shapes with single geometry commands.

The active page is switched to geometry edit mode, so when you select shapes you can see handles you can move to modify the geometry.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Geometry", "https://www.nevron.com/docs/openvision/diagram-shape-geometry.html"), ("Graphics Paths", "https://www.nevron.com/docs/openvision/graphics-paths.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"), }; } private void InitDiagram(NDrawingView drawingView) { NDrawingDocument drawingDocument = drawingView.Document; NDrawing drawing = drawingDocument.Content; // drawingView.Interactor.SingleEnableTool(NPe // switch selected edit mode to geometry // this instructs the diagram to show geometry handles for the selected shapes. drawing.ScreenVisibility.ShowGrid = false; // plotter commands CreateDescriptionPair(0, 0, CreateLineTo(), "Line To"); CreateDescriptionPair(0, 1, CreateArcTo(), "Arc To"); CreateDescriptionPair(0, 2, CreateCubicBezierTo(), "Cubic Bezier To"); CreateDescriptionPair(0, 3, CreateCircularArcTo(), "Circular Arc To"); CreateDescriptionPair(0, 4, CreateEllipticalArcTo(), "Elliptical Arc To"); // draw box commands CreateDescriptionPair(1, 0, CreateDrawRectangle(), "Draw Rectangle"); CreateDescriptionPair(1, 1, CreateDrawEllipse(), "Draw Ellipse"); CreateDescriptionPair(1, 2, CreateDrawPolygon(0), "Draw Polygon"); CreateDescriptionPair(1, 3, CreateDrawPolyline(0), "Draw Polyline"); CreateDescriptionPair(1, 4, CreateDrawPolygon(1), "Draw Polygon With Tension"); CreateDescriptionPair(1, 5, CreateDrawPolyline(1), "Draw Polyline With Tension"); CreateDescriptionPair(1, 6, CreateDrawPath(), "Draw Path"); } private NShape CreateLineTo() { NShape shape = new NShape(); shape.Init2DShape(); // the LineTo command draws a line from the prev plotter command to the command location { NMoveTo plotFigure = shape.Geometry.RelMoveTo(0, 0); shape.Geometry.RelLineTo(1, 1); plotFigure.ShowFill = false; } return shape; } private NShape CreateArcTo() { NShape shape = new NShape(); shape.Init2DShape(); // the ArcTo command draws a circular arc from the prev plotter command to the command location. // the ArcTo Bow parameter defines the distance of the arc from the line formed by previous command location and the command location { NMoveTo plotFigure = shape.Geometry.RelMoveTo(0, 0); shape.Geometry.RelArcTo(1, 1, 30); plotFigure.ShowFill = false; } return shape; } private NShape CreateCubicBezierTo() { NShape shape = new NShape(); shape.Init2DShape(); // the CubicBezierTo command draws a cubic bezier from the prev plotter command to the command location. // the cubic bezier curve is controled by two control points. { NMoveTo plotFigure = shape.Geometry.RelMoveTo(0, 0); shape.Geometry.RelCubicBezierTo(1, 1, 1, 0, 0, 1); plotFigure.ShowFill = false; } return shape; } private NShape CreateCircularArcTo() { NShape shape = new NShape(); shape.Init2DShape(); // the CircularAcrTo command draws a circular arc from the prev plotter command to the command location. // the circular acr curve is controled by a control point which defines the circle trough which the arc passes. { NMoveTo plotFigure = shape.Geometry.RelMoveTo(0, 0); shape.Geometry.RelCircularArcTo(1, 1, 1, 0); plotFigure.ShowFill = false; } return shape; } private NShape CreateEllipticalArcTo() { NShape shape = new NShape(); shape.Init2DShape(); // the EllipticalArcTo command draws an elliptical arc from the prev plotter command to the command location. // the elliptical acr curve is controled by a control point which defines the ellipse trough which the arc passes, // the angle of the ellipse and the ratio between the ellipse radiuses. { NMoveTo plotFigure = shape.Geometry.RelMoveTo(0, 0); shape.Geometry.RelEllipticalArcTo(1, 1, 1, 0, new NAngle(0, NUnit.Degree), 0.5); plotFigure.ShowFill = false; } return shape; } private NShape CreateDrawRectangle() { NShape shape = new NShape(); shape.Init2DShape(); // the draw rectangle command draws a rect inside a relative or absolute rect inside the shape coordinate system. // The following draws a rect that fills the shape. NDrawRectangle drawRectangle = new NDrawRectangle(0, 0, 1, 1); shape.Geometry.AddRelative(drawRectangle); return shape; } private NShape CreateDrawEllipse() { NShape shape = new NShape(); shape.Init2DShape(); // the draw ellipse command draws an ellipse inside a relative or absolute rect inside the shape coordinate system. // The following draws an ellipse that fills the shape. NDrawEllipse drawEllipse = new NDrawEllipse(0, 0, 1, 1); shape.Geometry.AddRelative(drawEllipse); return shape; } private NShape CreateDrawPolygon(double tension) { NShape shape = new NShape(); shape.Init2DShape(); NGenericNGram ngon = new NGenericNGram(4, 0, 0.5, 0.1, new NPoint(0.5, 0.5)); NPoint[] points = ngon.CreateVertices(); // the draw polygon command draws a polygon inside a relative or absolute rect inside the shape coordinate system. // The following draws a polygon that fills the shape. NDrawPolygon drawPolygon = new NDrawPolygon(0, 0, 1, 1, points); drawPolygon.Tension = tension; shape.Geometry.AddRelative(drawPolygon); return shape; } private NShape CreateDrawPolyline(double tension) { NShape shape = new NShape(); shape.Init2DShape(); NPoint[] points = new NPoint[] { new NPoint(0, 0), new NPoint(0.25, 1), new NPoint(0.50, 0), new NPoint(0.75, 1), new NPoint(1, 0), }; // the draw polyline command draws a polyline inside a relative or absolute rect inside the shape coordinate system. // The following draws a polyline that fills the shape. NDrawPolyline drawPolyline = new NDrawPolyline(0, 0, 1, 1, points); drawPolyline.Tension = tension; drawPolyline.ShowFill = false; shape.Geometry.AddRelative(drawPolyline); return shape; } private NShape CreateDrawPath() { NShape shape = new NShape(); shape.Init2DShape(); NGraphicsPath path = new NGraphicsPath(); path.AddRectangle(0, 0, 0.5, 0.5); path.AddEllipse(0.5, 0.5, 0.5, 0.5); // the draw path command draws a path inside a relative or absolute rect inside the shape coordinate system. // The following draws a path that contains a rectangle and an ellipse that fills the shape. NDrawPath drawPath = new NDrawPath(0, 0, 1, 1, path); shape.Geometry.AddRelative(drawPath); return shape; } private void CreateDescriptionPair(int row, int col, NShape shape, string text) { const double startX = 20; const double startY = 100; const double width = 80; const double height = 100; const double spacing = 20; m_DrawingView.ActivePage.Items.Add(shape); shape.SetBounds(new NRectangle(startX + col * (width + spacing), startY + row * (height + spacing), width, height / 2)); NShape textShape = new NShape(); textShape.Init2DShape(); textShape.Text = text; textShape.SetBounds(new NRectangle(startX + col * (width + spacing), startY + row * (height + spacing) + height / 2, width, height / 2)); m_DrawingView.ActivePage.Items.Add(textShape); } #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) Geometry Commands Example for WinForms Solution

VB.NET Geometry Commands Example Code for Nevron Diagram for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Diagram
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 - NGeometryCommandsExample"

        ' 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)
            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 "

Demonstrates the geometry commands that you can use to construct the shapes geometry.

On the first row you can see the different types of geometry commands that you can use to plot geometry. Plotter commands are designed to be placed in a sequence so that you can create arbitrary geometry by combining MoveTo, LineTo, CubicBezierTo, ArcTo, CircularActTo and EllipticalArcTo commands.

On the second row you can see the different types of draw box commands. These commands are used when you want to output more vertices or generally draw more complex clipart shapes with single geometry commands.

The active page is switched to geometry edit mode, so when you select shapes you can see handles you can move to modify the geometry.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Geometry", "https://www.nevron.com/docs/openvision/diagram-shape-geometry.html"), ("Graphics Paths", "https://www.nevron.com/docs/openvision/graphics-paths.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html")} End Function Private Sub InitDiagram(drawingView As NDrawingView) Dim drawingDocument = drawingView.Document Dim drawing = drawingDocument.Content ' drawingView.Interactor.SingleEnableTool(NPe ' switch selected edit mode to geometry ' this instructs the diagram to show geometry handles for the selected shapes. drawing.ScreenVisibility.ShowGrid = False ' plotter commands CreateDescriptionPair(0, 0, CreateLineTo(), "Line To") CreateDescriptionPair(0, 1, CreateArcTo(), "Arc To") CreateDescriptionPair(0, 2, CreateCubicBezierTo(), "Cubic Bezier To") CreateDescriptionPair(0, 3, CreateCircularArcTo(), "Circular Arc To") CreateDescriptionPair(0, 4, CreateEllipticalArcTo(), "Elliptical Arc To") ' draw box commands CreateDescriptionPair(1, 0, CreateDrawRectangle(), "Draw Rectangle") CreateDescriptionPair(1, 1, CreateDrawEllipse(), "Draw Ellipse") CreateDescriptionPair(1, 2, CreateDrawPolygon(0), "Draw Polygon") CreateDescriptionPair(1, 3, CreateDrawPolyline(0), "Draw Polyline") CreateDescriptionPair(1, 4, CreateDrawPolygon(1), "Draw Polygon With Tension") CreateDescriptionPair(1, 5, CreateDrawPolyline(1), "Draw Polyline With Tension") CreateDescriptionPair(1, 6, CreateDrawPath(), "Draw Path") End Sub Private Function CreateLineTo() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the LineTo command draws a line from the prev plotter command to the command location If True Then Dim plotFigure = shape.Geometry.RelMoveTo(0, 0) shape.Geometry.RelLineTo(1, 1) plotFigure.ShowFill = False End If Return shape End Function Private Function CreateArcTo() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the ArcTo command draws a circular arc from the prev plotter command to the command location. ' the ArcTo Bow parameter defines the distance of the arc from the line formed by previous command location and the command location If True Then Dim plotFigure = shape.Geometry.RelMoveTo(0, 0) shape.Geometry.RelArcTo(1, 1, 30) plotFigure.ShowFill = False End If Return shape End Function Private Function CreateCubicBezierTo() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the CubicBezierTo command draws a cubic bezier from the prev plotter command to the command location. ' the cubic bezier curve is controled by two control points. If True Then Dim plotFigure = shape.Geometry.RelMoveTo(0, 0) shape.Geometry.RelCubicBezierTo(1, 1, 1, 0, 0, 1) plotFigure.ShowFill = False End If Return shape End Function Private Function CreateCircularArcTo() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the CircularAcrTo command draws a circular arc from the prev plotter command to the command location. ' the circular acr curve is controled by a control point which defines the circle trough which the arc passes. If True Then Dim plotFigure = shape.Geometry.RelMoveTo(0, 0) shape.Geometry.RelCircularArcTo(1, 1, 1, 0) plotFigure.ShowFill = False End If Return shape End Function Private Function CreateEllipticalArcTo() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the EllipticalArcTo command draws an elliptical arc from the prev plotter command to the command location. ' the elliptical acr curve is controled by a control point which defines the ellipse trough which the arc passes, ' the angle of the ellipse and the ratio between the ellipse radiuses. If True Then Dim plotFigure = shape.Geometry.RelMoveTo(0, 0) shape.Geometry.RelEllipticalArcTo(1, 1, 1, 0, New NAngle(0, NUnit.Degree), 0.5) plotFigure.ShowFill = False End If Return shape End Function Private Function CreateDrawRectangle() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the draw rectangle command draws a rect inside a relative or absolute rect inside the shape coordinate system. ' The following draws a rect that fills the shape. Dim drawRectangle As NDrawRectangle = New NDrawRectangle(0, 0, 1, 1) shape.Geometry.AddRelative(drawRectangle) Return shape End Function Private Function CreateDrawEllipse() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() ' the draw ellipse command draws an ellipse inside a relative or absolute rect inside the shape coordinate system. ' The following draws an ellipse that fills the shape. Dim drawEllipse As NDrawEllipse = New NDrawEllipse(0, 0, 1, 1) shape.Geometry.AddRelative(drawEllipse) Return shape End Function Private Function CreateDrawPolygon(tension As Double) As NShape Dim shape As NShape = New NShape() shape.Init2DShape() Dim ngon As NGenericNGram = New NGenericNGram(4, 0, 0.5, 0.1, New NPoint(0.5, 0.5)) Dim points As NPoint() = ngon.CreateVertices() ' the draw polygon command draws a polygon inside a relative or absolute rect inside the shape coordinate system. ' The following draws a polygon that fills the shape. Dim drawPolygon As NDrawPolygon = New NDrawPolygon(0, 0, 1, 1, points) drawPolygon.Tension = tension shape.Geometry.AddRelative(drawPolygon) Return shape End Function Private Function CreateDrawPolyline(tension As Double) As NShape Dim shape As NShape = New NShape() shape.Init2DShape() Dim points As NPoint() = New NPoint() {New NPoint(0, 0), New NPoint(0.25, 1), New NPoint(0.50, 0), New NPoint(0.75, 1), New NPoint(1, 0)} ' the draw polyline command draws a polyline inside a relative or absolute rect inside the shape coordinate system. ' The following draws a polyline that fills the shape. Dim drawPolyline As NDrawPolyline = New NDrawPolyline(0, 0, 1, 1, points) drawPolyline.Tension = tension drawPolyline.ShowFill = False shape.Geometry.AddRelative(drawPolyline) Return shape End Function Private Function CreateDrawPath() As NShape Dim shape As NShape = New NShape() shape.Init2DShape() Dim path As NGraphicsPath = New NGraphicsPath() path.AddRectangle(0, 0, 0.5, 0.5) path.AddEllipse(0.5, 0.5, 0.5, 0.5) ' the draw path command draws a path inside a relative or absolute rect inside the shape coordinate system. ' The following draws a path that contains a rectangle and an ellipse that fills the shape. Dim drawPath As NDrawPath = New NDrawPath(0, 0, 1, 1, path) shape.Geometry.AddRelative(drawPath) Return shape End Function Private Sub CreateDescriptionPair(row As Integer, col As Integer, shape As NShape, text As String) Const startX As Double = 20 Const startY As Double = 100 Const width As Double = 80 Const height As Double = 100 Const spacing As Double = 20 m_DrawingView.ActivePage.Items.Add(shape) shape.SetBounds(New NRectangle(startX + col * (width + spacing), startY + row * (height + spacing), width, height / 2)) Dim textShape As NShape = New NShape() textShape.Init2DShape() textShape.Text = text textShape.SetBounds(New NRectangle(startX + col * (width + spacing), startY + row * (height + spacing) + height / 2, width, height / 2)) m_DrawingView.ActivePage.Items.Add(textShape) 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) Geometry Commands Example for WinForms Solution

Related Documentation Links