This example demonstrates how to apply character and word spacing.

| Language: C# |
using Nevron.Nov;
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.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NCharacterAndWordSpacingExample";
// 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();
m_CharacterSpacing = new NNumericUpDown();
m_CharacterSpacing.Value = 0;
m_CharacterSpacing.ValueChanged += OnCharacterSpacingFactorValueChanged;
m_WordSpacing = new NNumericUpDown();
m_WordSpacing.Value = 0;
m_WordSpacing.ValueChanged += OnWordSpacingFactorValueChanged;
stack.Add(new NPairBox(new NLabel("Character Spacing:"), m_CharacterSpacing, ENPairBoxRelation.Box1BeforeBox2));
stack.Add(new NPairBox(new NLabel("Word Spacing:"), m_WordSpacing, ENPairBoxRelation.Box1BeforeBox2));
return new NUniSizeBoxGroup(stack);
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to apply character and word spacing.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Rich Text Inline Elements", "https://www.nevron.com/docs/openvision/rich-text-inline-elements.html"),
("Rich Text Inline Styles", "https://www.nevron.com/docs/openvision/rich-text-inline-styles.html"),
};
}
private void PopulateRichText()
{
NSection section = new NSection();
m_RichText.Content.Sections.Add(section);
for (int i = 0; i < 3; i++)
{
NParagraph paragraph = new NParagraph();
section.Blocks.Add(paragraph);
paragraph.Inlines.Add(new NTextInline("This example demonstrates the ability to apply ", ENFontStyle.Underline));
if (i == 1)
{
paragraph.Inlines.Add(new NTextInline("Character and Word (This is inline with modified character and word spacing) ", ENFontStyle.BoldItalic));
}
paragraph.Inlines.Add(new NTextInline("spacing to inlines and individual blocks."));
if (i == 0)
{
paragraph.Inlines.Add(new NTextInline("This paragraph has modified character and word spacing. Use the controls on the right to set different word and character spacing"));
}
}
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnWordSpacingFactorValueChanged(NValueChangeEventArgs arg)
{
m_RichText.Content.Selection.SetWordSpacing((double)m_WordSpacing.Value);
}
private void OnCharacterSpacingFactorValueChanged(NValueChangeEventArgs arg)
{
m_RichText.Content.Selection.SetCharacterSpacing((double)m_CharacterSpacing.Value);
}
#endregion
#region Fields
private NRichTextView m_RichText;
private NNumericUpDown m_CharacterSpacing;
private NNumericUpDown m_WordSpacing;
#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
}
}