Report 2 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.

Report 2 Example for WinForms Description

This example demonstrates how to programmatically create reports as well as how to collect text elements of different type.


Sample Report 2Example

C# Report 2 Example Code for Nevron RichTextEditor for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.DataStructures;
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;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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()
		{
			NStackPanel stack = new NStackPanel();
			
			NButton highlightAllChartsButton = new NButton("Highlight All Charts");
			highlightAllChartsButton.Click += OnHighlightAllChartsButtonClick;
			stack.Add(highlightAllChartsButton);

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

This example demonstrates how to programmatically create reports as well as how to collect text elements of different type.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Tables", "https://www.nevron.com/docs/openvision/rich-text-tables.html"), ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html"), ("Rich Text Sections", "https://www.nevron.com/docs/openvision/rich-text-sections.html"), ("Rich Text Image Inlines", "https://www.nevron.com/docs/openvision/rich-text-image-inlines.html"), ("Rich Text Field Inlines", "https://www.nevron.com/docs/openvision/rich-text-field-inlines.html"), }; } private void PopulateRichText() { NSection section = new NSection(); m_RichText.Content.Sections.Add(section); NParagraph paragraph = new NParagraph(); paragraph.HorizontalAlignment = ENAlign.Center; paragraph.Inlines.Add(CreateHeaderText("ACME Corporation")); paragraph.Inlines.Add(new NLineBreakInline()); paragraph.Inlines.Add(CreateNormalText("Monthly Health Report")); section.Blocks.Add(paragraph); // generate sample data double[] sales = new double[12]; double[] hours = new double[12]; double[] profitloss = new double[12]; string[] months = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Random random = new Random(); for (int i = 0; i < 12; i++) { sales[i] = 50 + random.Next(50); hours[i] = 50 + random.Next(50); profitloss[i] = 25 - random.Next(50); } NTable table = new NTable(); section.Blocks.Add(table); table.Columns.Add(new NTableColumn()); table.Columns.Add(new NTableColumn()); { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Sales New Projects")); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(new NParagraph()); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Total Sales: " + GetTotal(sales).ToString())); par1.Inlines.Add(new NLineBreakInline()); par1.Inlines.Add(CreateNormalText("Last Month: " + sales[11].ToString())); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(CreateBarChart(true, new NSize(400, 200), "Sales", sales, months)); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Billable Hours: " + GetTotal(hours).ToString())); par1.Inlines.Add(new NLineBreakInline()); par1.Inlines.Add(CreateNormalText("Last Month: " + hours[11].ToString())); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(CreateBarChart(false, new NSize(400, 200), "Hours", hours, months)); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } { NTableRow tableRow = new NTableRow(); NTableCell tableCell1 = new NTableCell(); NParagraph par1 = new NParagraph(); par1.Inlines.Add(CreateHeaderText("Profit / Loss: " + GetTotal(profitloss).ToString())); par1.Inlines.Add(new NLineBreakInline()); par1.Inlines.Add(CreateNormalText("Last Month: " + profitloss[11].ToString())); tableCell1.Blocks.Add(par1); tableRow.Cells.Add(tableCell1); NTableCell tableCell2 = new NTableCell(); tableCell2.Blocks.Add(CreateBarChart(false, new NSize(400, 200), "Profit / Loss", hours, months)); tableRow.Cells.Add(tableCell2); table.Rows.Add(tableRow); } } #endregion #region Implementation #endregion #region Event Handlers void OnHighlightAllChartsButtonClick(NEventArgs arg) { NList charts = m_RichText.Content.GetDescendants(NChartView.NChartViewSchema); for (int i = 0; i < charts.Count; i++) { NChartView chartView = (NChartView)charts[i]; ((NCartesianChart)chartView.Surface.Charts[0]).PlotFill = new NColorFill(NColor.LightBlue); } } #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods private static double GetTotal(double[] values) { double total = 0.0; for (int i = 0; i < values.Length; i++) { total += values[i]; } return total; } private static NTextInline CreateHeaderText(string text) { NTextInline inline = new NTextInline(text); inline.FontSize = 14; inline.FontStyle = ENFontStyle.Bold; return inline; } private static NTextInline CreateNormalText(string text) { NTextInline inline = new NTextInline(text); inline.FontSize = 9; return inline; } /// /// Creates a sample bar chart given title, values and labels /// /// /// /// /// /// /// private static NParagraph CreateBarChart(bool area, NSize size, string title, double[] values, string[] labels) { NChartView chartView = new NChartView(); chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian); chartView.PreferredSize = size; // configure title chartView.Surface.Titles[0].Text = title; chartView.Surface.Titles[0].Margins = NMargins.Zero; chartView.Surface.Legends[0].Visibility = ENVisibility.Hidden; chartView.BorderThickness = NMargins.Zero; // configure chart NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0]; chart.Padding = new NMargins(20); chart.Margins = NMargins.Zero; if (area) { NAreaSeries areaSeries = new NAreaSeries(); areaSeries.LegendView.Mode = ENSeriesLegendMode.None; areaSeries.DataLabelStyle = new NDataLabelStyle(false); chart.Series.Add(areaSeries); for (int i = 0; i < values.Length; i++) { areaSeries.DataPoints.Add(new NAreaDataPoint(values[i])); } } else { NBarSeries barSeries = new NBarSeries(); barSeries.LegendView.Mode = ENSeriesLegendMode.None; barSeries.DataLabelStyle = new NDataLabelStyle(false); chart.Series.Add(barSeries); for (int i = 0; i < values.Length; i++) { barSeries.DataPoints.Add(new NBarDataPoint(values[i])); } } NOrdinalScale scaleX = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale; scaleX.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels); scaleX.MajorTickMode = ENMajorTickMode.CustomStep; scaleX.CustomStep = 1; NParagraph paragraph = new NParagraph(); NWidgetInline chartInline = new NWidgetInline(); chartInline.Content = chartView; paragraph.Inlines.Add(chartInline); return paragraph; } #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Report 2 Example for WinForms Solution

VB.NET Report 2 Example Code for Nevron RichTextEditor for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
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

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

        ' 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
            Dim stack As NStackPanel = New NStackPanel()

            Dim highlightAllChartsButton As NButton = New NButton("Highlight All Charts")
            highlightAllChartsButton.Click += AddressOf OnHighlightAllChartsButtonClick
            stack.Add(highlightAllChartsButton)

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

This example demonstrates how to programmatically create reports as well as how to collect text elements of different type.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Rich Text Tables", "https://www.nevron.com/docs/openvision/rich-text-tables.html"), ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html"), ("Rich Text Sections", "https://www.nevron.com/docs/openvision/rich-text-sections.html"), ("Rich Text Image Inlines", "https://www.nevron.com/docs/openvision/rich-text-image-inlines.html"), ("Rich Text Field Inlines", "https://www.nevron.com/docs/openvision/rich-text-field-inlines.html")} End Function Private Sub PopulateRichText() Dim section As NSection = New NSection() m_RichText.Content.Sections.Add(section) Dim paragraph As NParagraph = New NParagraph() paragraph.HorizontalAlignment = ENAlign.Center paragraph.Inlines.Add(CreateHeaderText("ACME Corporation")) paragraph.Inlines.Add(New NLineBreakInline()) paragraph.Inlines.Add(CreateNormalText("Monthly Health Report")) section.Blocks.Add(paragraph) ' generate sample data Dim sales = New Double(11) {} Dim hours = New Double(11) {} Dim profitloss = New Double(11) {} Dim months = New String() {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} Dim random As Random = New Random() For i = 0 To 11 sales(i) = 50 + random.Next(50) hours(i) = 50 + random.Next(50) profitloss(i) = 25 - random.Next(50) Next Dim table As NTable = New NTable() section.Blocks.Add(table) table.Columns.Add(New NTableColumn()) table.Columns.Add(New NTableColumn()) If True Then Dim tableRow As NTableRow = New NTableRow() Dim tableCell1 As NTableCell = New NTableCell() Dim par1 As NParagraph = New NParagraph() par1.Inlines.Add(CreateHeaderText("Sales New Projects")) tableCell1.Blocks.Add(par1) tableRow.Cells.Add(tableCell1) Dim tableCell2 As NTableCell = New NTableCell() tableCell2.Blocks.Add(New NParagraph()) tableRow.Cells.Add(tableCell2) table.Rows.Add(tableRow) End If If True Then Dim tableRow As NTableRow = New NTableRow() Dim tableCell1 As NTableCell = New NTableCell() Dim par1 As NParagraph = New NParagraph() par1.Inlines.Add(CreateHeaderText("Total Sales: " & GetTotal(sales).ToString())) par1.Inlines.Add(New NLineBreakInline()) par1.Inlines.Add(CreateNormalText("Last Month: " & sales(11).ToString())) tableCell1.Blocks.Add(par1) tableRow.Cells.Add(tableCell1) Dim tableCell2 As NTableCell = New NTableCell() tableCell2.Blocks.Add(CreateBarChart(True, New NSize(400, 200), "Sales", sales, months)) tableRow.Cells.Add(tableCell2) table.Rows.Add(tableRow) End If If True Then Dim tableRow As NTableRow = New NTableRow() Dim tableCell1 As NTableCell = New NTableCell() Dim par1 As NParagraph = New NParagraph() par1.Inlines.Add(CreateHeaderText("Billable Hours: " & GetTotal(hours).ToString())) par1.Inlines.Add(New NLineBreakInline()) par1.Inlines.Add(CreateNormalText("Last Month: " & hours(11).ToString())) tableCell1.Blocks.Add(par1) tableRow.Cells.Add(tableCell1) Dim tableCell2 As NTableCell = New NTableCell() tableCell2.Blocks.Add(CreateBarChart(False, New NSize(400, 200), "Hours", hours, months)) tableRow.Cells.Add(tableCell2) table.Rows.Add(tableRow) End If If True Then Dim tableRow As NTableRow = New NTableRow() Dim tableCell1 As NTableCell = New NTableCell() Dim par1 As NParagraph = New NParagraph() par1.Inlines.Add(CreateHeaderText("Profit / Loss: " & GetTotal(profitloss).ToString())) par1.Inlines.Add(New NLineBreakInline()) par1.Inlines.Add(CreateNormalText("Last Month: " & profitloss(11).ToString())) tableCell1.Blocks.Add(par1) tableRow.Cells.Add(tableCell1) Dim tableCell2 As NTableCell = New NTableCell() tableCell2.Blocks.Add(CreateBarChart(False, New NSize(400, 200), "Profit / Loss", hours, months)) tableRow.Cells.Add(tableCell2) table.Rows.Add(tableRow) End If End Sub #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnHighlightAllChartsButtonClick(arg As NEventArgs) Dim charts = m_RichText.Content.GetDescendants(NChartView.NChartViewSchema) For i = 0 To charts.Count - 1 Dim chartView = CType(charts(i), NChartView) CType(chartView.Surface.Charts(0), NCartesianChart).PlotFill = New NColorFill(NColor.LightBlue) Next End Sub #End Region #Region "Fields" Private m_RichText As NRichTextView #End Region #Region "Static Methods" Private Shared Function GetTotal(values As Double()) As Double Dim total = 0.0 For i = 0 To values.Length - 1 total += values(i) Next Return total End Function Private Shared Function CreateHeaderText(text As String) As NTextInline Dim inline As NTextInline = New NTextInline(text) inline.FontSize = 14 inline.FontStyle = ENFontStyle.Bold Return inline End Function Private Shared Function CreateNormalText(text As String) As NTextInline Dim inline As NTextInline = New NTextInline(text) inline.FontSize = 9 Return inline End Function ''' ''' Creates a sample bar chart given title, values and labels ''' ''' ''' ''' ''' ''' ''' Private Shared Function CreateBarChart(area As Boolean, size As NSize, title As String, values As Double(), labels As String()) As NParagraph Dim chartView As NChartView = New NChartView() chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian) chartView.PreferredSize = size ' configure title chartView.Surface.Titles(0).Text = title chartView.Surface.Titles(0).Margins = NMargins.Zero chartView.Surface.Legends(0).Visibility = ENVisibility.Hidden chartView.BorderThickness = NMargins.Zero ' configure chart Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart) chart.Padding = New NMargins(20) chart.Margins = NMargins.Zero If area Then Dim areaSeries As NAreaSeries = New NAreaSeries() areaSeries.LegendView.Mode = ENSeriesLegendMode.None areaSeries.DataLabelStyle = New NDataLabelStyle(False) chart.Series.Add(areaSeries) For i = 0 To values.Length - 1 areaSeries.DataPoints.Add(New NAreaDataPoint(values(i))) Next Else Dim barSeries As NBarSeries = New NBarSeries() barSeries.LegendView.Mode = ENSeriesLegendMode.None barSeries.DataLabelStyle = New NDataLabelStyle(False) chart.Series.Add(barSeries) For i = 0 To values.Length - 1 barSeries.DataPoints.Add(New NBarDataPoint(values(i))) Next End If Dim scaleX As NOrdinalScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale scaleX.Labels.TextProvider = New NOrdinalScaleLabelTextProvider(labels) scaleX.MajorTickMode = ENMajorTickMode.CustomStep scaleX.CustomStep = 1 Dim paragraph As NParagraph = New NParagraph() Dim chartInline As NWidgetInline = New NWidgetInline() chartInline.Content = chartView paragraph.Inlines.Add(chartInline) Return paragraph End Function #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Report 2 Example for WinForms Solution