Table Borders 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.

Table Borders Example for WinForms Description

This example demonstrates how table borders behave when the table allows or not table cells spacing.


Table Borders Example

C# Table Borders 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 - NTableBordersExample";

			// 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 table borders behave when the table allows or not table cells spacing.

"; } /// /// 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 Table Styles", "https://www.nevron.com/docs/openvision/rich-text-table-styles.html"), ("Rich Text Block Size", "https://www.nevron.com/docs/openvision/rich-text-block-size.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"), }; } private void PopulateRichText() { NSection section = new NSection(); m_RichText.Content.Sections.Add(section); { section.Blocks.Add(GetDescriptionBlock("Table Borders Example", "This example shows how table borders behave when the table allows or does not table cell spacing.", 1)); // first create the table NTable table = CreateTable(2, 3); table.AllowSpacingBetweenCells = true; table.TableCellHorizontalSpacing = 3; table.TableCellVerticalSpacing = 3; for (int col = 0; col < table.Columns.Count; col++) { for (int row = 0; row < table.Rows.Count; row++) { NTableCell cell = table.Rows[row].Cells[col]; switch (col % 3) { case 0: cell.Border = NBorder.CreateFilledBorder(NColor.Red); cell.Margins = new NMargins(3); cell.Padding = new NMargins(3); cell.BorderThickness = new NMargins(1); break; case 1: cell.Border = NBorder.CreateFilledBorder(NColor.Green); cell.Margins = new NMargins(5); cell.Padding = new NMargins(5); cell.BorderThickness = new NMargins(3); break; case 2: cell.Border = NBorder.CreateFilledBorder(NColor.Blue); cell.Margins = new NMargins(7); cell.Padding = new NMargins(7); cell.BorderThickness = new NMargins(2); break; } } } table.Border = NBorder.CreateFilledBorder(NColor.Red); table.BorderThickness = new NMargins(2, 2, 2, 2); section.Blocks.Add(table); section.Blocks.Add(new NParagraph("This is a 2x3 table, with borders in collapsed table border mode:")); // first create the table table = CreateTable(2, 3); table.AllowSpacingBetweenCells = false; for (int col = 0; col < table.Columns.Count; col++) { for (int row = 0; row < table.Rows.Count; row++) { NTableCell cell = table.Rows[row].Cells[col]; switch (col % 3) { case 0: cell.Border = NBorder.CreateFilledBorder(NColor.Red); cell.Margins = new NMargins(3); cell.Padding = new NMargins(3); cell.BorderThickness = new NMargins(1); break; case 1: cell.Border = NBorder.CreateFilledBorder(NColor.Green); cell.Margins = new NMargins(5); cell.Padding = new NMargins(5); cell.BorderThickness = new NMargins(3); break; case 2: cell.Border = NBorder.CreateFilledBorder(NColor.Blue); cell.Margins = new NMargins(7); cell.Padding = new NMargins(7); cell.BorderThickness = new NMargins(2); break; } } } table.Border = NBorder.CreateFilledBorder(NColor.Red); section.Blocks.Add(table); } } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods private static NTable CreateTable(int rowCount, int colCount) { // first create the table NTable table = new NTable(rowCount, colCount); table.AllowSpacingBetweenCells = true; table.TableCellHorizontalSpacing = 3; table.TableCellVerticalSpacing = 3; for (int col = 0; col < table.Columns.Count; col++) { // set table column preferred width string headerText = string.Empty; switch (col) { case 0: // Fixed column table.Columns[col].PreferredWidth = new NMultiLength(ENMultiLengthUnit.Dip, 80); headerText = "Fixed [80dips]"; break; case 1: // Auto headerText = "Automatic"; break; case 2: // Percentage table.Columns[col].PreferredWidth = new NMultiLength(ENMultiLengthUnit.Percentage, 20); headerText = "Percentage [20%]"; break; case 3: // Fixed table.Columns[col].PreferredWidth = new NMultiLength(ENMultiLengthUnit.Dip, 160); headerText = "Fixed [160dips]"; break; case 4: // Percentage table.Columns[col].PreferredWidth = new NMultiLength(ENMultiLengthUnit.Percentage, 30); headerText = "Percentage [30%]"; break; } for (int row = 0; row < table.Rows.Count; row++) { NParagraph paragraph; if (row == 0) { paragraph = new NParagraph(headerText); } else { paragraph = new NParagraph("Cell"); } NTableCell cell = table.Rows[row].Cells[col]; cell.Blocks.Clear(); cell.Blocks.Add(paragraph); } } return table; } 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) Table Borders Example for WinForms Solution

VB.NET Table Borders 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 - NTableBordersExample"

        ' 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 table borders behave when the table allows or not table cells spacing.

" 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 Table Styles", "https://www.nevron.com/docs/openvision/rich-text-table-styles.html"), ("Rich Text Block Size", "https://www.nevron.com/docs/openvision/rich-text-block-size.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html")} End Function Private Sub PopulateRichText() Dim section As NSection = New NSection() m_RichText.Content.Sections.Add(section) If True Then section.Blocks.Add(GetDescriptionBlock("Table Borders Example", "This example shows how table borders behave when the table allows or does not table cell spacing.", 1)) ' first create the table Dim table = CreateTable(2, 3) table.AllowSpacingBetweenCells = True table.TableCellHorizontalSpacing = 3 table.TableCellVerticalSpacing = 3 For col = 0 To table.Columns.Count - 1 For row = 0 To table.Rows.Count - 1 Dim cell = table.Rows(row).Cells(col) Select Case col Mod 3 Case 0 cell.Border = NBorder.CreateFilledBorder(NColor.Red) cell.Margins = New NMargins(3) cell.Padding = New NMargins(3) cell.BorderThickness = New NMargins(1) Case 1 cell.Border = NBorder.CreateFilledBorder(NColor.Green) cell.Margins = New NMargins(5) cell.Padding = New NMargins(5) cell.BorderThickness = New NMargins(3) Case 2 cell.Border = NBorder.CreateFilledBorder(NColor.Blue) cell.Margins = New NMargins(7) cell.Padding = New NMargins(7) cell.BorderThickness = New NMargins(2) End Select Next Next table.Border = NBorder.CreateFilledBorder(NColor.Red) table.BorderThickness = New NMargins(2, 2, 2, 2) section.Blocks.Add(table) section.Blocks.Add(New NParagraph("This is a 2x3 table, with borders in collapsed table border mode:")) ' first create the table table = CreateTable(2, 3) table.AllowSpacingBetweenCells = False For col = 0 To table.Columns.Count - 1 For row = 0 To table.Rows.Count - 1 Dim cell = table.Rows(row).Cells(col) Select Case col Mod 3 Case 0 cell.Border = NBorder.CreateFilledBorder(NColor.Red) cell.Margins = New NMargins(3) cell.Padding = New NMargins(3) cell.BorderThickness = New NMargins(1) Case 1 cell.Border = NBorder.CreateFilledBorder(NColor.Green) cell.Margins = New NMargins(5) cell.Padding = New NMargins(5) cell.BorderThickness = New NMargins(3) Case 2 cell.Border = NBorder.CreateFilledBorder(NColor.Blue) cell.Margins = New NMargins(7) cell.Padding = New NMargins(7) cell.BorderThickness = New NMargins(2) End Select Next Next table.Border = NBorder.CreateFilledBorder(NColor.Red) section.Blocks.Add(table) End If 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" Private Shared Function CreateTable(rowCount As Integer, colCount As Integer) As NTable ' first create the table Dim table As NTable = New NTable(rowCount, colCount) table.AllowSpacingBetweenCells = True table.TableCellHorizontalSpacing = 3 table.TableCellVerticalSpacing = 3 For col = 0 To table.Columns.Count - 1 ' set table column preferred width Dim headerText = String.Empty Select Case col Case 0 ' Fixed column table.Columns(col).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Dip, 80) headerText = "Fixed [80dips]" Case 1 ' Auto headerText = "Automatic" Case 2 ' Percentage table.Columns(col).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 20) headerText = "Percentage [20%]" Case 3 ' Fixed table.Columns(col).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Dip, 160) headerText = "Fixed [160dips]" Case 4 ' Percentage table.Columns(col).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, 30) headerText = "Percentage [30%]" End Select For row = 0 To table.Rows.Count - 1 Dim paragraph As NParagraph If row = 0 Then paragraph = New NParagraph(headerText) Else paragraph = New NParagraph("Cell") End If Dim cell = table.Rows(row).Cells(col) cell.Blocks.Clear() cell.Blocks.Add(paragraph) Next Next Return table End Function Private Shared Function GetDescriptionParagraph(text As String) As NParagraph Return New NParagraph(text) End Function Private Shared Function GetTitleParagraphNoBorder(text As String, level As Integer) As NParagraph Dim fontSize As Double = 10 Dim fontStyle = ENFontStyle.Regular Select Case level Case 1 fontSize = 16 fontStyle = ENFontStyle.Bold Case 2 fontSize = 10 fontStyle = ENFontStyle.Bold End Select Dim paragraph As NParagraph = New NParagraph() paragraph.HorizontalAlignment = ENAlign.Left paragraph.FontSize = fontSize paragraph.FontStyle = fontStyle Dim textInline As NTextInline = New NTextInline(text) textInline.FontStyle = fontStyle textInline.FontSize = fontSize paragraph.Inlines.Add(textInline) Return paragraph End Function Private Shared Function GetDescriptionBlock(title As String, description As String, level As Integer) As NGroupBlock Dim color = NColor.Black Dim paragraph = GetTitleParagraphNoBorder(title, level) Dim groupBlock As NGroupBlock = New NGroupBlock() groupBlock.ClearMode = ENClearMode.All groupBlock.Blocks.Add(paragraph) groupBlock.Blocks.Add(GetDescriptionParagraph(description)) groupBlock.Border = CreateLeftTagBorder(color) groupBlock.BorderThickness = defaultBorderThickness Return groupBlock End Function ''' ''' Creates a left tag border with the specified border ''' ''' ''' Private Shared Function CreateLeftTagBorder(color As NColor) As NBorder Dim border As NBorder = New NBorder() border.LeftSide = New NBorderSide() border.LeftSide.Fill = New NColorFill(color) Return border End Function #End Region #Region "Constants" Private Shared ReadOnly defaultBorderThickness As NMargins = New NMargins(5.0, 0.0, 0.0, 0.0) #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Table Borders Example for WinForms Solution