Document Statistics 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.

Document Statistics Example for WinForms Description

The example demonstrates how to get document statistics about character count, word count etc.


Document Statistics Example

C# Document Statistics 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.Text;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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
			m_RichText = new NRichTextView();
			m_RichText.AcceptsTab = true;
			m_RichText.Content.Sections.Clear();

			// set to print to have page count statistics
			m_RichText.Content.Layout = ENTextLayout.Print;

			// add some content
			NSection section = new NSection();

			for (int i = 0; i < 10; i++)
			{
				string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumstring.";
				section.Blocks.Add(new NParagraph(text));
			}

			m_RichText.Content.Sections.Add(section);

			m_RichText.HRuler.Visibility = ENVisibility.Visible;
			m_RichText.VRuler.Visibility = ENVisibility.Visible;

			return m_RichText;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();

			NButton statisticsButton = new NButton("Get Statistics");
			statisticsButton.Click += StatisticsButton_Click;
			stack.Add(statisticsButton);

			m_StatisticsTextBox = new NTextBox();
			m_StatisticsTextBox.Multiline = true;
			m_StatisticsTextBox.ReadOnly = true;
			stack.Add(m_StatisticsTextBox);

			return stack;
		}
		public string GetExampleDescription()
		{
			return "

The example demonstrates how to get document statistics about character count, word count etc.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Documents - Overview", "https://www.nevron.com/docs/openvision/rich-text-documents-overview.html"), ("Rich Text Programming Model Overview", "https://www.nevron.com/docs/openvision/rich-text-programming-model-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void StatisticsButton_Click(NEventArgs arg) { StringBuilder builder = new StringBuilder(); builder.AppendLine("Character Count: " + m_RichText.Content.Statistics.CharactersWithSpacesCount.ToString()); builder.AppendLine("Word Count: " + m_RichText.Content.Statistics.WordCount.ToString()); builder.AppendLine("Line Count: " + m_RichText.Content.Statistics.LineCount.ToString()); builder.AppendLine("Paragraph Count: " + m_RichText.Content.Statistics.ParagraphCount.ToString()); builder.AppendLine("Page Count: " + m_RichText.Content.Statistics.PageCount.ToString()); m_StatisticsTextBox.Text = builder.ToString(); } #endregion #region Fields private NRichTextView m_RichText; private NTextBox m_StatisticsTextBox; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Document Statistics Example for WinForms Solution

VB.NET Document Statistics 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
Imports System.Text

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

        ' 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
            m_RichText = New NRichTextView()
            m_RichText.AcceptsTab = True
            m_RichText.Content.Sections.Clear()

            ' set to print to have page count statistics
            m_RichText.Content.Layout = ENTextLayout.Print

            ' add some content
            Dim section As NSection = New NSection()

            For i = 0 To 9
                Dim text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborumstring."
                section.Blocks.Add(New NParagraph(text))
            Next

            m_RichText.Content.Sections.Add(section)

            m_RichText.HRuler.Visibility = ENVisibility.Visible
            m_RichText.VRuler.Visibility = ENVisibility.Visible

            Return m_RichText
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim statisticsButton As NButton = New NButton("Get Statistics")
            statisticsButton.Click += AddressOf StatisticsButton_Click
            stack.Add(statisticsButton)

            m_StatisticsTextBox = New NTextBox()
            m_StatisticsTextBox.Multiline = True
            m_StatisticsTextBox.ReadOnly = True
            stack.Add(m_StatisticsTextBox)

            Return stack
        End Function
        Public Function GetExampleDescription() As String
            Return "

The example demonstrates how to get document statistics about character count, word count etc.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Rich Text Documents - Overview", "https://www.nevron.com/docs/openvision/rich-text-documents-overview.html"), ("Rich Text Programming Model Overview", "https://www.nevron.com/docs/openvision/rich-text-programming-model-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub StatisticsButton_Click(arg As NEventArgs) Dim builder As StringBuilder = New StringBuilder() builder.AppendLine("Character Count: " & m_RichText.Content.Statistics.CharactersWithSpacesCount.ToString()) builder.AppendLine("Word Count: " & m_RichText.Content.Statistics.WordCount.ToString()) builder.AppendLine("Line Count: " & m_RichText.Content.Statistics.LineCount.ToString()) builder.AppendLine("Paragraph Count: " & m_RichText.Content.Statistics.ParagraphCount.ToString()) builder.AppendLine("Page Count: " & m_RichText.Content.Statistics.PageCount.ToString()) m_StatisticsTextBox.Text = builder.ToString() End Sub #End Region #Region "Fields" Private m_RichText As NRichTextView Private m_StatisticsTextBox As NTextBox #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) Document Statistics Example for WinForms Solution