Custom Drawing Tools 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.

Custom Drawing Tools Example for WinForms Description

This example demonstrates how to create custom drawing tools. Click on a shape and the custom click select tool of this example will select it together with its ancestor and descendant shapes.


Custom Drawing Tools Example

C# Custom Drawing Tools Example Code for Nevron Diagram for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Diagram;
using Nevron.Nov.Diagram.DrawingTools;
using Nevron.Nov.Diagram.Layout;
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 - NCustomDrawingToolsExample";

			// 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()
		{
			NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
			NDrawingView drawingView = drawingViewWithRibbon.View;

			// Configure the selection
			NDrawingSettings drawingSettings = drawingView.Settings;
			drawingSettings.ShowSelectionBoxTrackers = false;
			drawingSettings.ShowSelectionPinRotationTrackers = false;

			// Change selection outline colors
			drawingSettings.SelectedOutlineStroke = new NStroke(3, NColor.Firebrick);
			drawingSettings.FormatAnchorOutlineStroke = new NStroke(4, NColor.Orange);
			drawingSettings.AlignmentAnchorOutlineStroke = (NStroke)drawingSettings.SelectedOutlineStroke.DeepClone();

			// Replace the default pointer tool with the ancestor and descendants pointer tool
			drawingView.Interactor.ReplaceTool();

			drawingView.Document.HistoryService.Pause();
			try
			{
				InitDiagram(drawingView.Document);

				// Set selection anchor modes
				drawingView.ActivePage.Selection.FormatAnchorMode = ENSelectionAnchorMode.First;
				drawingView.ActivePage.Selection.AlignmentAnchorMode = ENSelectionAnchorMode.First;
			}
			finally
			{
				drawingView.Document.HistoryService.Resume();
			}

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

This example demonstrates how to create custom drawing tools. Click on a shape and the custom click select tool of this example will select it together with its ancestor and descendant shapes.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Drawing View Tools", "https://www.nevron.com/docs/openvision/diagram-drawing-view-tools.html"), ("Interactors", "https://www.nevron.com/docs/openvision/ui-interactors.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { const double width = 40; const double height = 40; const double distance = 80; // Hide ports drawingDocument.Content.ScreenVisibility.ShowPorts = false; NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NPage activePage = drawingDocument.Content.ActivePage; int[] from = new int[] { 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6 }; int[] to = new int[] { 2, 3, 4, 4, 5, 6, 7, 5, 9, 8, 9 }; NShape[] shapes = new NShape[9]; int vertexCount = shapes.Length, edgeCount = from.Length; int i, j, count = vertexCount + edgeCount; for (i = 0; i < count; i++) { if (i < vertexCount) { j = vertexCount % 2 == 0 ? i : i + 1; shapes[i] = basicShapes.CreateShape(ENBasicShape.Rectangle); if (vertexCount % 2 != 0 && i == 0) { shapes[i].SetBounds(new NRectangle( (width + (distance * 1.5)) / 2, distance + (j / 2) * (distance * 1.5), width, height)); } else { shapes[i].SetBounds(new NRectangle( width / 2 + (j % 2) * (distance * 1.5), height + (j / 2) * (distance * 1.5), width, height)); } activePage.Items.Add(shapes[i]); } else { NRoutableConnector edge = new NRoutableConnector(); edge.UserClass = NDR.StyleSheetNameConnectors; activePage.Items.Add(edge); edge.GlueBeginToShape(shapes[from[i - vertexCount] - 1]); edge.GlueEndToShape(shapes[to[i - vertexCount] - 1]); } } // arrange diagram ArrangeDiagram(drawingDocument); // fit active page drawingDocument.Content.ActivePage.ZoomMode = ENZoomMode.Fit; } /// /// Arranges the shapes in the active page. /// /// private void ArrangeDiagram(NDrawingDocument drawingDocument) { // get all top-level shapes that reside in the active page NPage activePage = drawingDocument.Content.ActivePage; NList shapes = activePage.GetShapes(false); // create a layout context and use it to arrange the shapes using the current layout NDrawingLayoutContext layoutContext = new NDrawingLayoutContext(drawingDocument, activePage); NLayeredGraphLayout layout = new NLayeredGraphLayout(); layout.Arrange(shapes.CastAll(), layoutContext); // size the page to the content size activePage.SizeToContent(); } #endregion #region Implementation /// /// Selects the ancestors and descendants of the given shape. /// /// private void SelectShapeAncestorsAndDescendants(NShape shape) { if (shape.ShapeType == ENShapeType.Shape2D) { SelectShape(shape, true, true); } else { SelectConnector(shape, true, true); } } private void SelectShape(NShape shape, bool selectIncomingConnectors, bool selectOutgoingConnectors) { if (shape == null) return; NPage page = shape.OwnerPage; NPageSelection selection = page.Selection; if (!selection.IsSelected(shape)) { selection.MultiSelect(shape); } if (selectIncomingConnectors) { // Select incoming connectors NList incomingConnectors = shape.GetIncomingShapes(); for (int i = 0; i < incomingConnectors.Count; i++) { SelectConnector(incomingConnectors[i], true, false); } } if (selectOutgoingConnectors) { // Select outgonig connectors NList outgoingConnectors = shape.GetOutgoingShapes(); for (int i = 0; i < outgoingConnectors.Count; i++) { SelectConnector(outgoingConnectors[i], false, true); } } } private void SelectConnector(NShape connector, bool selectFromShape, bool selectToShape) { NPage page = connector.OwnerPage; NPageSelection selection = page.Selection; if (!selection.IsSelected(connector)) { selection.MultiSelect(connector); } if (selectFromShape) { SelectShape(connector.FromShape, true, false); } if (selectToShape) { SelectShape(connector.ToShape, false, true); } } #endregion #region Event Handlers #endregion #region Fields #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types internal class AncestorsAndDescendantsPointerTool : NCompositeTool { #region Constructors /// /// Default constructor. /// public AncestorsAndDescendantsPointerTool() { AddEnabledTool(new AncestorsAndDescendantsClickSelectTool()); } /// /// Static constructor. /// static AncestorsAndDescendantsPointerTool() { AncestorsAndDescendantsPointerToolSchema = NSchema.Create(typeof(AncestorsAndDescendantsPointerTool), NCompositeToolSchema); } #endregion #region Schema /// /// Schema associated with AncestorsAndDescendantsPointerTool. /// public static readonly NSchema AncestorsAndDescendantsPointerToolSchema; #endregion } internal class AncestorsAndDescendantsClickSelectTool : NClickSelectTool { #region Constructors /// /// Default constructor. /// public AncestorsAndDescendantsClickSelectTool() { } /// /// Static constructor. /// static AncestorsAndDescendantsClickSelectTool() { AncestorsAndDescendantsClickSelectToolSchema = NSchema.Create(typeof(AncestorsAndDescendantsClickSelectTool), NClickSelectToolSchema); } #endregion #region Protected Overrides protected override void ClickSelect(INPointerEventArgs args) { NPageSelection selection = OwnerDrawingView?.ActivePage?.Selection; if (selection != null) { selection.DeselectAll(); } base.ClickSelect(args); if (args.TargetNode == null) return; // Make sure only 1 item is selected NShape clickedShape = args.TargetNode.GetFirstAncestor(); if (clickedShape != null) { SelectShapeAncestorsAndDescendants(clickedShape); } } protected override void DrillDownSelect(INPointerEventArgs args) { base.DrillDownSelect(args); // Get the page NPage page = OwnerDrawingView.ActivePage; if (page == null) return; // Get the page selection NPageSelection selection = page.Selection; // Make sure only 1 shape is selected if (selection.SelectedCount == 1 && selection.FirstSelected is NShape shape) { SelectShapeAncestorsAndDescendants(shape); } } #endregion #region Implementation /// /// Selects the ancestors and descendants of the given shape. /// /// private void SelectShapeAncestorsAndDescendants(NShape shape) { if (shape.ShapeType == ENShapeType.Shape2D) { SelectShape(shape, true, true); } else { SelectConnector(shape, true, true); } } private void SelectShape(NShape shape, bool selectIncomingConnectors, bool selectOutgoingConnectors) { if (shape == null) return; NPage page = shape.OwnerPage; NPageSelection selection = page.Selection; if (!selection.IsSelected(shape)) { selection.MultiSelect(shape); } if (selectIncomingConnectors) { // Select incoming connectors NList incomingConnectors = shape.GetIncomingShapes(); for (int i = 0; i < incomingConnectors.Count; i++) { SelectConnector(incomingConnectors[i], true, false); } } if (selectOutgoingConnectors) { // Select outgonig connectors NList outgoingConnectors = shape.GetOutgoingShapes(); for (int i = 0; i < outgoingConnectors.Count; i++) { SelectConnector(outgoingConnectors[i], false, true); } } } private void SelectConnector(NShape connector, bool selectFromShape, bool selectToShape) { NPage page = connector.OwnerPage; NPageSelection selection = page.Selection; if (!selection.IsSelected(connector)) { selection.MultiSelect(connector); } if (selectFromShape) { SelectShape(connector.FromShape, true, false); } if (selectToShape) { SelectShape(connector.ToShape, false, true); } } #endregion #region Schema /// /// Schema associated with AncestorsAndDescendantsClickSelectTool. /// public static readonly NSchema AncestorsAndDescendantsClickSelectToolSchema; #endregion } #endregion } }

Download a fully functional C# (.cs) Custom Drawing Tools Example for WinForms Solution

VB.NET Custom Drawing Tools Example Code for Nevron Diagram for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.DataStructures
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.DrawingTools
Imports Nevron.Nov.Diagram.Layout
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 - NCustomDrawingToolsExample"

        ' 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 Nevron.Nov.UI.NWidget
            Dim drawingViewWithRibbon As Nevron.Nov.Diagram.NDrawingViewWithRibbon = New Nevron.Nov.Diagram.NDrawingViewWithRibbon()
            Dim drawingView As Nevron.Nov.Diagram.NDrawingView = drawingViewWithRibbon.View

            ' Configure the selection
            Dim drawingSettings As Nevron.Nov.Diagram.NDrawingSettings = drawingView.Settings
            drawingSettings.ShowSelectionBoxTrackers = False
            drawingSettings.ShowSelectionPinRotationTrackers = False

            ' Change selection outline colors
            drawingSettings.SelectedOutlineStroke = New Nevron.Nov.Graphics.NStroke(3, Nevron.Nov.Graphics.NColor.Firebrick)
            drawingSettings.FormatAnchorOutlineStroke = New Nevron.Nov.Graphics.NStroke(4, Nevron.Nov.Graphics.NColor.Orange)
            drawingSettings.AlignmentAnchorOutlineStroke = CType(drawingSettings.SelectedOutlineStroke.DeepClone(), Nevron.Nov.Graphics.NStroke)

            ' Replace the default pointer tool with the ancestor and descendants pointer tool
            drawingView.Interactor.ReplaceTool(Of Nevron.Nov.Diagram.DrawingTools.NPointerTool, Nevron.Nov.Examples.Diagram.NCustomDrawingToolsExample.AncestorsAndDescendantsPointerTool)()

            drawingView.Document.HistoryService.Pause()
            Try
                Me.InitDiagram(drawingView.Document)

                ' Set selection anchor modes
                drawingView.ActivePage.Selection.FormatAnchorMode = Nevron.Nov.UI.ENSelectionAnchorMode.First
                drawingView.ActivePage.Selection.AlignmentAnchorMode = Nevron.Nov.UI.ENSelectionAnchorMode.First
            Finally
                drawingView.Document.HistoryService.[Resume]()
            End Try

            Return drawingViewWithRibbon
        End Function
        Public Function CreateExampleControls() As Nevron.Nov.UI.NWidget
            Return Nothing
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create custom drawing tools. Click on a shape and the custom click select tool of this example will select it together with its ancestor and descendant shapes.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Drawing View Tools", "https://www.nevron.com/docs/openvision/diagram-drawing-view-tools.html"), ("Interactors", "https://www.nevron.com/docs/openvision/ui-interactors.html")} End Function Private Sub InitDiagram(drawingDocument As Nevron.Nov.Diagram.NDrawingDocument) Const width As Double = 40 Const height As Double = 40 Const distance As Double = 80 ' Hide ports drawingDocument.Content.ScreenVisibility.ShowPorts = False Dim basicShapes As Nevron.Nov.Diagram.Shapes.NBasicShapeFactory = New Nevron.Nov.Diagram.Shapes.NBasicShapeFactory() Dim activePage As Nevron.Nov.Diagram.NPage = drawingDocument.Content.ActivePage Dim from As Integer() = New Integer() {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6} Dim [to] As Integer() = New Integer() {2, 3, 4, 4, 5, 6, 7, 5, 9, 8, 9} Dim shapes As Nevron.Nov.Diagram.NShape() = New Nevron.Nov.Diagram.NShape(8) {} Dim vertexCount As Integer = shapes.Length, edgeCount As Integer = from.Length Dim i, j As Integer, count As Integer = vertexCount + edgeCount For i = 0 To count - 1 If i < vertexCount Then j = If(vertexCount Mod 2 = 0, i, i + 1) shapes(i) = basicShapes.CreateShape(Nevron.Nov.Diagram.Shapes.ENBasicShape.Rectangle) If vertexCount Mod 2 <> 0 AndAlso i = 0 Then shapes(CInt((i))).SetBounds(New Nevron.Nov.Graphics.NRectangle((width + (distance * 1.5)) / 2, distance + (j / 2) * (distance * 1.5), width, height)) Else shapes(CInt((i))).SetBounds(New Nevron.Nov.Graphics.NRectangle(width / 2 + (j Mod 2) * (distance * 1.5), height + (j / 2) * (distance * 1.5), width, height)) End If activePage.Items.Add(shapes(i)) Else Dim edge As Nevron.Nov.Diagram.NRoutableConnector = New Nevron.Nov.Diagram.NRoutableConnector() edge.UserClass = Nevron.Nov.Diagram.NDR.StyleSheetNameConnectors activePage.Items.Add(edge) edge.GlueBeginToShape(shapes(from(i - vertexCount) - 1)) edge.GlueEndToShape(shapes([to](i - vertexCount) - 1)) End If Next ' arrange diagram Me.ArrangeDiagram(drawingDocument) ' fit active page drawingDocument.Content.ActivePage.ZoomMode = Nevron.Nov.UI.ENZoomMode.Fit End Sub ''' ''' Arranges the shapes in the active page. ''' ''' Private Sub ArrangeDiagram(drawingDocument As Nevron.Nov.Diagram.NDrawingDocument) ' get all top-level shapes that reside in the active page Dim activePage As Nevron.Nov.Diagram.NPage = drawingDocument.Content.ActivePage Dim shapes As Nevron.Nov.DataStructures.NList(Of Nevron.Nov.Diagram.NShape) = activePage.GetShapes(False) ' create a layout context and use it to arrange the shapes using the current layout Dim layoutContext As Nevron.Nov.Diagram.Layout.NDrawingLayoutContext = New Nevron.Nov.Diagram.Layout.NDrawingLayoutContext(drawingDocument, activePage) Dim layout As Nevron.Nov.Diagram.Layout.NLayeredGraphLayout = New Nevron.Nov.Diagram.Layout.NLayeredGraphLayout() layout.Arrange(shapes.CastAll(Of Object)(), layoutContext) ' size the page to the content size activePage.SizeToContent() End Sub #End Region #Region "Implementation" ''' ''' Selects the ancestors and descendants of the given shape. ''' ''' Private Sub SelectShapeAncestorsAndDescendants(shape As Nevron.Nov.Diagram.NShape) If shape.ShapeType Is Nevron.Nov.Diagram.ENShapeType.Shape2D Then Me.SelectShape(shape, True, True) Else Me.SelectConnector(shape, True, True) End If End Sub Private Sub SelectShape(shape As Nevron.Nov.Diagram.NShape, selectIncomingConnectors As Boolean, selectOutgoingConnectors As Boolean) If shape Is Nothing Then Return Dim page As Nevron.Nov.Diagram.NPage = shape.OwnerPage Dim selection As Nevron.Nov.Diagram.NPageSelection = page.Selection If Not selection.IsSelected(shape) Then selection.MultiSelect(shape) End If If selectIncomingConnectors Then ' Select incoming connectors Dim incomingConnectors As Nevron.Nov.DataStructures.NList(Of Nevron.Nov.Diagram.NShape) = shape.GetIncomingShapes() For i As Integer = 0 To incomingConnectors.Count - 1 Me.SelectConnector(incomingConnectors(i), True, False) Next End If If selectOutgoingConnectors Then ' Select outgonig connectors Dim outgoingConnectors As Nevron.Nov.DataStructures.NList(Of Nevron.Nov.Diagram.NShape) = shape.GetOutgoingShapes() For i As Integer = 0 To outgoingConnectors.Count - 1 Me.SelectConnector(outgoingConnectors(i), False, True) Next End If End Sub Private Sub SelectConnector(connector As Nevron.Nov.Diagram.NShape, selectFromShape As Boolean, selectToShape As Boolean) Dim page As Nevron.Nov.Diagram.NPage = connector.OwnerPage Dim selection As Nevron.Nov.Diagram.NPageSelection = page.Selection If Not selection.IsSelected(connector) Then selection.MultiSelect(connector) End If If selectFromShape Then Me.SelectShape(connector.FromShape, True, False) End If If selectToShape Then Me.SelectShape(connector.ToShape, False, True) End If End Sub #End Region #Region "Event Handlers" #End Region #Region "Fields" #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" Friend Class AncestorsAndDescendantsPointerTool Inherits Nevron.Nov.UI.NCompositeTool #Region "Constructors" ''' ''' Default constructor. ''' Public Sub New() MyBase.AddEnabledTool(New Nevron.Nov.Examples.Diagram.NCustomDrawingToolsExample.AncestorsAndDescendantsClickSelectTool()) End Sub ''' ''' Static constructor. ''' Shared Sub New() Nevron.Nov.Examples.Diagram.NCustomDrawingToolsExample.AncestorsAndDescendantsPointerTool.AncestorsAndDescendantsPointerToolSchema = Nevron.Nov.Dom.NSchema.Create(GetType(Nevron.Nov.Examples.Diagram.NCustomDrawingToolsExample.AncestorsAndDescendantsPointerTool), Nevron.Nov.UI.NCompositeTool.NCompositeToolSchema) End Sub #End Region #Region "Schema" ''' ''' Schema associated with AncestorsAndDescendantsPointerTool. ''' Public Shared ReadOnly AncestorsAndDescendantsPointerToolSchema As Nevron.Nov.Dom.NSchema #End Region End Class Friend Class AncestorsAndDescendantsClickSelectTool Inherits Nevron.Nov.Diagram.DrawingTools.NClickSelectTool #Region "Constructors" ''' ''' Default constructor. ''' Public Sub New() End Sub ''' ''' Static constructor. ''' Shared Sub New() Nevron.Nov.Examples.Diagram.NCustomDrawingToolsExample.AncestorsAndDescendantsClickSelectTool.AncestorsAndDescendantsClickSelectToolSchema = Nevron.Nov.Dom.NSchema.Create(GetType(Nevron.Nov.Examples.Diagram.NCustomDrawingToolsExample.AncestorsAndDescendantsClickSelectTool), Nevron.Nov.Diagram.DrawingTools.NClickSelectTool.NClickSelectToolSchema) End Sub #End Region #Region "Protected Overrides" Protected Overrides Sub ClickSelect(args As Nevron.Nov.UI.INPointerEventArgs) Dim selection As Nevron.Nov.Diagram.NPageSelection = MyBase.OwnerDrawingView?.ActivePage?.Selection If selection IsNot Nothing Then selection.DeselectAll() End If MyBase.ClickSelect(args) If args.TargetNode Is Nothing Then Return ' Make sure only 1 item is selected Dim clickedShape As Nevron.Nov.Diagram.NShape = args.TargetNode.GetFirstAncestor(Of Nevron.Nov.Diagram.NShape)() If clickedShape IsNot Nothing Then Me.SelectShapeAncestorsAndDescendants(clickedShape) End If End Sub Protected Overrides Sub DrillDownSelect(args As Nevron.Nov.UI.INPointerEventArgs) MyBase.DrillDownSelect(args) ' Get the page Dim page As Nevron.Nov.Diagram.NPage = MyBase.OwnerDrawingView.ActivePage If page Is Nothing Then Return ' Get the page selection Dim selection As Nevron.Nov.Diagram.NPageSelection = page.Selection Dim shape As Nevron.Nov.Diagram.NShape = Nothing ' Make sure only 1 shape is selected If selection.SelectedCount = 1 AndAlso CSharpImpl.__Assign(shape, TryCast(selection.FirstSelected, Nevron.Nov.Diagram.NShape)) IsNot Nothing Then Me.SelectShapeAncestorsAndDescendants(shape) End If End Sub #End Region #Region "Implementation" ''' ''' Selects the ancestors and descendants of the given shape. ''' ''' Private Sub SelectShapeAncestorsAndDescendants(shape As Nevron.Nov.Diagram.NShape) If shape.ShapeType Is Nevron.Nov.Diagram.ENShapeType.Shape2D Then Me.SelectShape(shape, True, True) Else Me.SelectConnector(shape, True, True) End If End Sub Private Sub SelectShape(shape As Nevron.Nov.Diagram.NShape, selectIncomingConnectors As Boolean, selectOutgoingConnectors As Boolean) If shape Is Nothing Then Return Dim page As Nevron.Nov.Diagram.NPage = shape.OwnerPage Dim selection As Nevron.Nov.Diagram.NPageSelection = page.Selection If Not selection.IsSelected(shape) Then selection.MultiSelect(shape) End If If selectIncomingConnectors Then ' Select incoming connectors Dim incomingConnectors As Nevron.Nov.DataStructures.NList(Of Nevron.Nov.Diagram.NShape) = shape.GetIncomingShapes() For i As Integer = 0 To incomingConnectors.Count - 1 Me.SelectConnector(incomingConnectors(i), True, False) Next End If If selectOutgoingConnectors Then ' Select outgonig connectors Dim outgoingConnectors As Nevron.Nov.DataStructures.NList(Of Nevron.Nov.Diagram.NShape) = shape.GetOutgoingShapes() For i As Integer = 0 To outgoingConnectors.Count - 1 Me.SelectConnector(outgoingConnectors(i), False, True) Next End If End Sub Private Sub SelectConnector(connector As Nevron.Nov.Diagram.NShape, selectFromShape As Boolean, selectToShape As Boolean) Dim page As Nevron.Nov.Diagram.NPage = connector.OwnerPage Dim selection As Nevron.Nov.Diagram.NPageSelection = page.Selection If Not selection.IsSelected(connector) Then selection.MultiSelect(connector) End If If selectFromShape Then Me.SelectShape(connector.FromShape, True, False) End If If selectToShape Then Me.SelectShape(connector.ToShape, False, True) End If End Sub #End Region #Region "Schema" ''' ''' Schema associated with AncestorsAndDescendantsClickSelectTool. ''' Public Shared ReadOnly AncestorsAndDescendantsClickSelectToolSchema As Nevron.Nov.Dom.NSchema Private Class CSharpImpl Shared Function __Assign(Of T)(ByRef target As T, value As T) As T target = value Return value End Function End Class #End Region End Class #End Region End Class

Download a fully functional VB.NET (.vb) Custom Drawing Tools Example for WinForms Solution

Related Documentation Links