HTML Text 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.

HTML Text Example for WinForms Description

Demonstrates how to set HTML formatted text to a diagram shape via the SetHtmlContent method of the shape's text block.


Html Text Example

C# HTML Text Example Code for Nevron Diagram for WinForms
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.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

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

Demonstrates how to set HTML formatted text to a diagram shape via the SetHtmlContent method of the shape's text block.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Text Block", "https://www.nevron.com/docs/openvision/diagram-text-block.html"), ("Rich Text - Loading Documents", "https://www.nevron.com/docs/openvision/rich-text-loading-documents.html"), ("Rich Text Editor Formats", "https://www.nevron.com/docs/openvision/rich-text-editor-formats.html"), }; } private void InitDiagram(NDrawingDocument document) { NBasicShapeFactory factory = new NBasicShapeFactory(); NPage page = document.Content.ActivePage; NShape shape1 = factory.CreateShape(ENBasicShape.Rectangle); shape1.SetBounds(100, 100, 150, 100); page.Items.Add(shape1); NTextBlock textBlock = (NTextBlock)shape1.TextBlock; textBlock.Padding = new NMargins(5); textBlock.SetHtmlContent("Html text with bold, italic and red"); } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) HTML Text Example for WinForms Solution

VB.NET HTML Text Example Code for Nevron Diagram for WinForms
Language: VB.NET

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

        ' 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
            Dim drawingViewWithRibbon As NDrawingViewWithRibbon = New NDrawingViewWithRibbon()
            Dim drawingView = drawingViewWithRibbon.View

            drawingView.Document.HistoryService.Pause()
            Try
                InitDiagram(drawingView.Document)
            Finally
                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 how to set HTML formatted text to a diagram shape via the SetHtmlContent method of the shape's text block.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Text Block", "https://www.nevron.com/docs/openvision/diagram-text-block.html"), ("Rich Text - Loading Documents", "https://www.nevron.com/docs/openvision/rich-text-loading-documents.html"), ("Rich Text Editor Formats", "https://www.nevron.com/docs/openvision/rich-text-editor-formats.html")} End Function Private Sub InitDiagram(document As NDrawingDocument) Dim factory As NBasicShapeFactory = New NBasicShapeFactory() Dim page = document.Content.ActivePage Dim shape1 = factory.CreateShape(ENBasicShape.Rectangle) shape1.SetBounds(100, 100, 150, 100) page.Items.Add(shape1) Dim textBlock = CType(shape1.TextBlock, NTextBlock) textBlock.Padding = New NMargins(5) textBlock.SetHtmlContent("Html text with bold, italic and red") End Sub #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" #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) HTML Text Example for WinForms Solution