Size Example for Blazor

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

Size Example for Blazor Description

This example demonstrates how to control the size of text blocks using the preferred, minimum and maximum width and height properties of each block element.


Block Size Example

C# Size Example Code for Nevron RichTextEditor for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
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 - NBlockSizeExample";

			// 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 the rich text
			NRichTextViewWithRibbon richTextWithRibbon = new NRichTextViewWithRibbon();
			m_RichText = richTextWithRibbon.View;
			m_RichText.AcceptsTab = true;
			m_RichText.Content.Sections.Clear();

			// Populate the rich text
			PopulateRichText();

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

This example demonstrates how to control the size of text blocks using the preferred, minimum and maximum width and height properties of each block element.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Block Size", "https://www.nevron.com/docs/openvision/rich-text-block-size.html"), ("Rich Text Block Elements", "https://www.nevron.com/docs/openvision/rich-text-block-elements.html"), }; } private void PopulateRichText() { NSection section = new NSection(); m_RichText.Content.Sections.Add(section); section.Blocks.Add(GetDescriptionBlock("Block Size", "Every block in the document can have a specified Preferred, Minimum and Maximum size.", 1)); section.Blocks.Add(GetDescriptionBlock("Preferred Width and Height", "The following paragraph has specified Preferred Width and Height.", 2)); NParagraph paragraph1 = new NParagraph("Paragraph with Preferred Width 50% and Preferred Height of 200dips."); paragraph1.BackgroundFill = new NColorFill(NColor.LightGray); paragraph1.PreferredWidth = new NMultiLength(ENMultiLengthUnit.Percentage, 50); paragraph1.PreferredHeight = new NMultiLength(ENMultiLengthUnit.Dip, 200); section.Blocks.Add(paragraph1); section.Blocks.Add(GetDescriptionBlock("Minimum and Maximum Width and Height", "The following paragraph has specified Minimum and Maximum Width.", 2)); NParagraph paragraph2 = new NParagraph("Paragraph with Preferred Width 50% and Preferred Height of 200dips and Minimum Width of 200 dips and Maximum Width 300 dips."); paragraph2.BackgroundFill = new NColorFill(NColor.LightGray); paragraph2.PreferredWidth = new NMultiLength(ENMultiLengthUnit.Percentage, 50); paragraph2.PreferredHeight = new NMultiLength(ENMultiLengthUnit.Dip, 200); paragraph2.MinWidth = new NMultiLength(ENMultiLengthUnit.Dip, 200); paragraph2.MaxWidth = new NMultiLength(ENMultiLengthUnit.Dip, 300); paragraph2.WrapDesiredWidth = false; paragraph2.WrapMinWidth = false; section.Blocks.Add(paragraph2); section.Blocks.Add(GetDescriptionBlock("Desired Width Wrapping", "The following paragraph has disabled desired width wrapping, resulting in a paragraph that does not introduce any hard line breaks.", 2)); NParagraph paragraph3 = new NParagraph("Paragraph with WrapDesiredWidth set to false. Note that the paragraph will not introduce any hard breaks. The content of this paragraph is intentionally made long to illustrate this feature."); paragraph3.BackgroundFill = new NColorFill(NColor.LightGray); paragraph3.WrapDesiredWidth = false; paragraph3.WrapMinWidth = false; section.Blocks.Add(paragraph3); } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods private static NParagraph GetDescriptionParagraph(string text) { return new NParagraph(text); } private static NParagraph GetTitleParagraphNoBorder(string text, int level) { double fontSize = 10; ENFontStyle fontStyle = ENFontStyle.Regular; switch (level) { case 1: fontSize = 16; fontStyle = ENFontStyle.Bold; break; case 2: fontSize = 10; fontStyle = ENFontStyle.Bold; break; } NParagraph paragraph = new NParagraph(); paragraph.HorizontalAlignment = ENAlign.Left; paragraph.FontSize = fontSize; paragraph.FontStyle = fontStyle; NTextInline textInline = new NTextInline(text); textInline.FontStyle = fontStyle; textInline.FontSize = fontSize; paragraph.Inlines.Add(textInline); return paragraph; } private static NGroupBlock GetDescriptionBlock(string title, string description, int level) { NColor color = NColor.Black; NParagraph paragraph = GetTitleParagraphNoBorder(title, level); NGroupBlock groupBlock = new NGroupBlock(); groupBlock.ClearMode = ENClearMode.All; groupBlock.Blocks.Add(paragraph); groupBlock.Blocks.Add(GetDescriptionParagraph(description)); groupBlock.Border = CreateLeftTagBorder(color); groupBlock.BorderThickness = defaultBorderThickness; return groupBlock; } /// /// Creates a left tag border with the specified border /// /// /// private static NBorder CreateLeftTagBorder(NColor color) { NBorder border = new NBorder(); border.LeftSide = new NBorderSide(); border.LeftSide.Fill = new NColorFill(color); return border; } #endregion #region Constants private static readonly NMargins defaultBorderThickness = new NMargins(5.0, 0.0, 0.0, 0.0); #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Size Example for Blazor Solution