This example demonstrates how to add hyperlinks to shapes. Shape hyperlinks allow you to navigate to an URL, page, shape, bookmark or to open a file. Ctrl + Click on a shape with hyperlink to navigate to the hyperlink target.

| 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.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NShapeHyperlinksExample";
// 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;
drawingView.Document.HistoryService.Pause();
try
{
InitDiagram(drawingView.Document);
}
finally
{
drawingView.Document.HistoryService.Resume();
}
return drawingViewWithRibbon;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to add hyperlinks to shapes. Shape hyperlinks allow you to navigate to an URL, page, shape, bookmark or to open a file.
Ctrl + Click on a shape with hyperlink to navigate to the hyperlink target.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Shape Hyperlink", "https://www.nevron.com/docs/openvision/diagram-shape-hyperlink.html"),
("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"),
};
}
private void InitDiagram(NDrawingDocument drawingDocument)
{
const double TitleWidth = 100;
const double TitleFontSize = 16;
// Get the drawing and the active (first) page
NDrawing drawing = drawingDocument.Content;
NPage page1 = drawing.ActivePage;
// Create a second page and a bookmark on it
NPage page2 = new NPage();
drawing.Pages.Add(page2);
NBookmark bookmark = new NBookmark("MyBookmark", 0, 0, 1.5);
page2.BookmarkManager.Bookmarks.Add(bookmark);
NBasicShapeFactory factory = new NBasicShapeFactory();
factory.DefaultSize = new NSize(160, 100);
// Page 1
NShape title1 = new NShape();
title1.Text = "Page 1";
title1.SetBounds((page1.Width - TitleWidth) / 2, 20, TitleWidth, 30);
title1.TextBlock.FontSize = TitleFontSize;
page1.Items.Add(title1);
NShape shape1 = factory.CreateShape(ENBasicShape.Ellipse);
shape1.SetPinPoint(100, 200);
shape1.Text = "Go to page 2";
shape1.Hyperlink = new NShapeHyperlink(page2);
shape1.Ports.RemoveAt(0);
shape1.Style = new NShapeStyle(101, 101);
page1.Items.Add(shape1);
NShape shape2 = factory.CreateShape(ENBasicShape.SixPointStar);
shape2.SetPinPoint(350, 200);
shape2.Size = new NSize(150, 150);
shape2.Text = "Go to" + Environment.NewLine + bookmark.Name;
shape2.Hyperlink = new NShapeHyperlink(bookmark);
shape2.Ports.RemoveAt(0);
shape2.Style = new NShapeStyle(103, 103);
page1.Items.Add(shape2);
NShape shape3 = factory.CreateShape(ENBasicShape.Rectangle);
shape3.SetPinPoint(100, 400);
shape3.Text = "www.nevron.com";
shape3.Hyperlink = new NShapeHyperlink("https://www.nevron.com");
shape3.Ports.RemoveAt(0);
page1.Items.Add(shape3);
// Page 2
NShape title2 = new NShape();
title2.Text = "Page 2";
title2.SetBounds((page2.Width - TitleWidth) / 2, 20, TitleWidth, 30);
title2.TextBlock.FontSize = TitleFontSize;
page2.Items.Add(title2);
NShape shape4 = factory.CreateShape(ENBasicShape.Ellipse);
shape4.SetPinPoint(100, 200);
shape4.Text = "Go to page 1";
shape4.Hyperlink = new NShapeHyperlink(page1);
shape4.Ports.RemoveAt(0);
shape4.Style = new NShapeStyle(102, 102);
page2.Items.Add(shape4);
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}