Flowchart (Install Program) Example for Blazor

Flowchart (Install Program) Example for Blazor

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

Flowchart (Install Program) Example for Blazor Description

Demonstrates how to create a flowchart that describes a Software Installation process.


Install Program Example

C# Flowchart (Install Program) Example Code for Nevron Diagram for Blazor
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.IO;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NInstallProgramExample";

			// 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 @"

Demonstrates how to create a flowchart that describes a Software Installation process.

"; } /// /// 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"), ("Routable Connectors", "https://www.nevron.com/docs/openvision/diagram-routable-connectors.html"), ("Layered Graph Layout", "https://www.nevron.com/docs/openvision/diagram-layered-graph-layout.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { NStyleSheet sheet = new NStyleSheet(); drawingDocument.StyleSheets.Add(sheet); // create a rule that applies to the geometries of all shapes with user class Connectors { NRule rule = sheet.CreateRule(delegate (NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass(NDR.StyleSheetNameConnectors); }); rule.AddValueDeclaration(NGeometry.EndArrowheadProperty, new NArrowhead(ENArrowheadShape.TriangleNoFill), true); } // create a rule that applies to the TextBlocks of all shapes with user class Connectors { NRule rule = sheet.CreateRule(delegate (NSelectorBuilder sb) { sb.Type(NTextBlock.NTextBlockSchema); sb.ChildOf(); sb.UserClass(NDR.StyleSheetNameConnectors); }); rule.AddValueDeclaration(NTextBlock.BackgroundFillProperty, new NColorFill(NColor.White)); } // create a rule that applies to shapes with user class "STARTEND" { NRule rule = sheet.CreateRule(delegate (NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("STARTEND"); }); rule.AddValueDeclaration(NGeometry.FillProperty, new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, new NColor(247, 150, 56), new NColor(251, 203, 156))); } // create a rule that applies to shapes with user class "QUESTION" { NRule rule = sheet.CreateRule(delegate (NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("QUESTION"); }); rule.AddValueDeclaration(NGeometry.FillProperty, new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, new NColor(129, 133, 133), new NColor(192, 194, 194))); } // create a rule that applies to shapes with user class "ACTION" { NRule rule = sheet.CreateRule(delegate (NSelectorBuilder sb) { sb.Type(NGeometry.NGeometrySchema); sb.ChildOf(); sb.UserClass("ACTION"); }); rule.AddValueDeclaration(NGeometry.FillProperty, new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, new NColor(68, 90, 108), new NColor(162, 173, 182))); } // get drawing and active page NDrawing drawing = drawingDocument.Content; NPage activePage = drawing.ActivePage; // hide ports and grid drawing.ScreenVisibility.ShowGrid = false; drawing.ScreenVisibility.ShowPorts = false; int vSpacing = 35; int hSpacing = 45; int topMargin = 10; int leftMargin = 10; int shapeWidth = 90; int shapeHeight = 55; int col1 = leftMargin; int col2 = col1 + shapeWidth + hSpacing; int col3 = col2 + shapeWidth + hSpacing; int col4 = col3 + shapeWidth + hSpacing; int row1 = topMargin; int row2 = row1 + shapeHeight + vSpacing; int row3 = row2 + shapeHeight + vSpacing; int row4 = row3 + shapeHeight + vSpacing; int row5 = row4 + shapeHeight + vSpacing; int row6 = row5 + shapeHeight + vSpacing; NFlowchartShapeFactory flowchartShapes = new NFlowchartShapeFactory(); NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory(); NRectangle bounds = new NRectangle(col2, row1, shapeWidth, shapeHeight); NShape start = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Termination, bounds, "START", "STARTEND"); // row 2 bounds = new NRectangle(col2, row2, shapeWidth, shapeHeight); NShape haveSerialNumber = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Decision, bounds, "Have a serial number?", "QUESTION"); bounds = new NRectangle(col3, row2, shapeWidth, shapeHeight); NShape getSerialNumber = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Get serial number", "ACTION"); // row 3 bounds = new NRectangle(col1, row3, shapeWidth, shapeHeight); NShape enterSerialNumber = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Enter serial number", "ACTION"); bounds = new NRectangle(col2, row3, shapeWidth, shapeHeight); NShape haveDiskSpace = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Decision, bounds, "Have disk space?", "QUESTION"); bounds = new NRectangle(col3, row3, shapeWidth, shapeHeight); NShape freeUpSpace = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Free up space", "ACTION"); // row 4 bounds = new NRectangle(col1, row4, shapeWidth, shapeHeight); NShape runInstallRect = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Run install file", "ACTION"); bounds = new NRectangle(col2, row4, shapeWidth, shapeHeight); NShape registerNow = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Decision, bounds, "Register now?", "QUESTION"); bounds = new NRectangle(col3, row4, shapeWidth, shapeHeight); NShape fillForm = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Fill out form", "ACTION"); bounds = new NRectangle(col4, row4, shapeWidth, shapeHeight); NShape submitForm = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Submit form", "ACTION"); // row 5 bounds = new NRectangle(col1, row5, shapeWidth, shapeHeight); NShape finishInstall = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Finish installation", "ACTION"); bounds = new NRectangle(col2, row5, shapeWidth, shapeHeight); NShape restartNeeded = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Decision, bounds, "Restart needed?", "QUESTION"); bounds = new NRectangle(col3, row5, shapeWidth, shapeHeight); NShape restart = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "Restart", "ACTION"); // row 6 bounds = new NRectangle(col2, row6, shapeWidth, shapeHeight); NShape run = CreateFlowchartShape(flowchartShapes, ENFlowchartShape.Process, bounds, "RUN", "STARTEND"); // create connectors CreateConnector(start, "Bottom", haveSerialNumber, "Top", ENConnectorShape.Line, ""); CreateConnector(getSerialNumber, "Top", haveSerialNumber, "Top", ENConnectorShape.RoutableConnector, ""); CreateConnector(haveSerialNumber, "Right", getSerialNumber, "Left", ENConnectorShape.Line, "No"); CreateConnector(haveSerialNumber, "Bottom", enterSerialNumber, "Top", ENConnectorShape.BottomToTop1, "Yes"); CreateConnector(enterSerialNumber, "Right", haveDiskSpace, "Left", ENConnectorShape.Line, ""); CreateConnector(freeUpSpace, "Top", haveDiskSpace, "Top", ENConnectorShape.RoutableConnector, ""); CreateConnector(haveDiskSpace, "Right", freeUpSpace, "Left", ENConnectorShape.Line, "No"); CreateConnector(haveDiskSpace, "Bottom", runInstallRect, "Top", ENConnectorShape.BottomToTop1, "Yes"); CreateConnector(registerNow, "Right", fillForm, "Left", ENConnectorShape.Line, "Yes"); CreateConnector(registerNow, "Bottom", finishInstall, "Top", ENConnectorShape.BottomToTop1, "No"); CreateConnector(fillForm, "Right", submitForm, "Left", ENConnectorShape.Line, ""); CreateConnector(submitForm, "Bottom", finishInstall, "Top", ENConnectorShape.BottomToTop1, ""); CreateConnector(finishInstall, "Right", restartNeeded, "Left", ENConnectorShape.Line, ""); CreateConnector(restart, "Bottom", run, "Top", ENConnectorShape.BottomToTop1, ""); CreateConnector(restartNeeded, "Right", restart, "Left", ENConnectorShape.Line, "Yes"); CreateConnector(restartNeeded, "Bottom", run, "Top", ENConnectorShape.Line, "No"); } #endregion #region Implementation /// /// Creates a predefined basic shape /// /// basic shape /// bounds /// default label text /// name of the stylesheet from which to inherit styles /// new basic shape private NShape CreateBasicShape(ENBasicShape basicShape, NRectangle bounds, string text, string userClass) { // create shape NShape shape = m_BasicShapes.CreateShape(basicShape); // set bounds, text and user class shape.SetBounds(bounds); shape.Text = text; shape.UserClass = userClass; // add to active page m_DrawingView.ActivePage.Items.Add(shape); return shape; } /// /// Creates a predefined flowchart shape. /// /// flowchart shape /// bounds /// default label text /// name of the stylesheet from which to inherit styles /// new basic shape private NShape CreateFlowchartShape(NFlowchartShapeFactory flowchartShapeFactory, ENFlowchartShape flowChartShape, NRectangle bounds, string text, string userClass) { // create shape NShape shape = flowchartShapeFactory.CreateShape(flowChartShape); // set bounds, text and user class shape.SetBounds(bounds); shape.Text = text; shape.UserClass = userClass; // add to active page m_DrawingView.ActivePage.Items.Add(shape); return shape; } /// /// Creates a new connector, which connects the specified shapes /// /// /// /// /// /// /// /// new 1D shapes private NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ENConnectorShape connectorType, string text) { // check arguments if (fromShape == null) throw new ArgumentNullException("fromShape"); if (toShape == null) throw new ArgumentNullException("toShape"); // create the connector NShape connector = m_ConnectorShapes.CreateShape(connectorType); // set text and user class connector.Text = text; connector.UserClass = NDR.StyleSheetNameConnectors; // connect begin NPort fromPort = fromShape.Ports.GetPortByName(fromPortName); if (fromPort != null) { connector.GlueBeginToPort(fromPort); } else { connector.GlueBeginToShape(fromShape); } // connect end NPort toPort = toShape.Ports.GetPortByName(toPortName); if (toPort != null) { connector.GlueEndToPort(toPort); } else { connector.GlueEndToShape(toShape); } // add to active page m_DrawingView.ActivePage.Items.Add(connector); return connector; } #endregion #region Event Handlers #endregion #region Fields private NDrawingView m_DrawingView; private NPoint m_GridOrigin = new NPoint(30, 30); private NSize m_GridCellSize = new NSize(180, 70); private NSize m_GridSpacing = new NSize(50, 40); private NBasicShapeFactory m_BasicShapes = new NBasicShapeFactory(); private NConnectorShapeFactory m_ConnectorShapes = new NConnectorShapeFactory(); #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Flowchart (Install Program) Example for Blazor Solution