Paragraph Styles Example for WinForms

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

Paragraph Styles Example for WinForms Description

This example demonstrates how to create and apply paragraph styles.


Paragraph Styles Example

C# Paragraph Styles Example Code for Nevron RichTextEditor for WinForms
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.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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 create and apply paragraph styles.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Paragraph Styles", "https://www.nevron.com/docs/openvision/rich-text-paragraph-styles.html"), ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html"), }; } private void PopulateRichText() { NDocumentBlock documentBlock = m_RichText.Content; NSection section = new NSection(); documentBlock.Sections.Add(section); // Create the first paragraph NParagraph paragraph1 = new NParagraph("This paragraph is styled with a predefined paragraph style."); section.Blocks.Add(paragraph1); // Apply a predefined paragraph style NRichTextStyle predefinedStyle = documentBlock.Styles.FindStyleByTypeAndId(ENRichTextStyleType.Paragraph, "Heading2"); predefinedStyle.Apply(paragraph1); // Create the second paragraph NParagraph paragraph2 = new NParagraph("This paragraph is styled with a custom paragraph style."); section.Blocks.Add(paragraph2); // Create a custom paragraph style and apply it NParagraphStyle customStyle = new NParagraphStyle("CustomStyle"); customStyle.ParagraphRule = new NParagraphRule(); customStyle.ParagraphRule.BorderRule = new NBorderRule(ENPredefinedBorderStyle.Dash, NColor.Red, new NMargins(1)); customStyle.ParagraphRule.HorizontalAlignment = ENAlign.Center; customStyle.ParagraphRule.Padding = new NMargins(20); customStyle.InlineRule = new NInlineRule(); customStyle.InlineRule.Fill = new NColorFill(NColor.Blue); customStyle.Apply(paragraph2); paragraph2.MarginTop = 30; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Paragraph Styles Example for WinForms Solution

VB.NET Paragraph Styles Example Code for Nevron RichTextEditor for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Text
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 - NParagraphStylesExample"

        ' 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
            ' Create the rich text
            Dim richTextWithRibbon As NRichTextViewWithRibbon = New NRichTextViewWithRibbon()
            m_RichText = richTextWithRibbon.View
            m_RichText.AcceptsTab = True
            m_RichText.Content.Sections.Clear()

            ' Populate the rich text
            PopulateRichText()

            Return richTextWithRibbon
        End Function
        Public Function CreateExampleControls() As NWidget
            Return Nothing
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create and apply paragraph styles.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Rich Text Paragraph Styles", "https://www.nevron.com/docs/openvision/rich-text-paragraph-styles.html"), ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html")} End Function Private Sub PopulateRichText() Dim documentBlock = m_RichText.Content Dim section As NSection = New NSection() documentBlock.Sections.Add(section) ' Create the first paragraph Dim paragraph1 As NParagraph = New NParagraph("This paragraph is styled with a predefined paragraph style.") section.Blocks.Add(paragraph1) ' Apply a predefined paragraph style Dim predefinedStyle = documentBlock.Styles.FindStyleByTypeAndId(ENRichTextStyleType.Paragraph, "Heading2") predefinedStyle.Apply(paragraph1) ' Create the second paragraph Dim paragraph2 As NParagraph = New NParagraph("This paragraph is styled with a custom paragraph style.") section.Blocks.Add(paragraph2) ' Create a custom paragraph style and apply it Dim customStyle As NParagraphStyle = New NParagraphStyle("CustomStyle") customStyle.ParagraphRule = New NParagraphRule() customStyle.ParagraphRule.BorderRule = New NBorderRule(ENPredefinedBorderStyle.Dash, NColor.Red, New NMargins(1)) customStyle.ParagraphRule.HorizontalAlignment = ENAlign.Center customStyle.ParagraphRule.Padding = New NMargins(20) customStyle.InlineRule = New NInlineRule() customStyle.InlineRule.Fill = New NColorFill(NColor.Blue) customStyle.Apply(paragraph2) paragraph2.MarginTop = 30 End Sub #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_RichText As NRichTextView #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) Paragraph Styles Example for WinForms Solution