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

HTML Text Example for Blazor 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 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.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 Blazor Solution