The example demonstrates the DOCX import capabilities of the Nevron Rich Text control.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.Text.Formats;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using static Nevron.Nov.UI.NCommandBarDock;
using System;
using System.IO;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NDocxImportExample";
// 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();
return richTextWithRibbon;
}
public NWidget CreateExampleControls()
{
NGroupBox predefinedDocumentGroupBox = CreatePredefinedDocumentGroupBox();
predefinedDocumentGroupBox.VerticalPlacement = ENVerticalPlacement.Top;
return predefinedDocumentGroupBox;
}
public string GetExampleDescription()
{
return @"The example demonstrates the DOCX import capabilities of the Nevron Rich Text control.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Rich Text - Loading Documents", "https://www.nevron.com/docs/openvision/rich-text-loading-documents.html"),
("Rich Text Editor Formats", "https://www.nevron.com/docs/openvision/rich-text-editor-formats.html"),
};
}
#endregion
#region Implementation
private NGroupBox CreatePredefinedDocumentGroupBox()
{
const string DocxSuffix = "_docx";
NEmbeddedResource[] sampleDocxDocuments = new NEmbeddedResource[] { Nevron.Nov.Examples.NResources.RBIN_DOCX_CompatibilityTest_docx,
Nevron.Nov.Examples.NResources.RBIN_DOCX_ComplexDocument_docx,
Nevron.Nov.Examples.NResources.RBIN_DOCX_EventInvitation_docx,
Nevron.Nov.Examples.NResources.RBIN_DOCX_InvoiceTemplate_docx };
NListBox testListBox = new NListBox();
for (int i = 0; i < sampleDocxDocuments.Length; i++)
{
NEmbeddedResource sampleDocxDocument = sampleDocxDocuments[i];
// The current resource is a DOCX document, so add it to the list box
string testName = sampleDocxDocument.Name.Substring("RBIN_DOCX_".Length);
testName = testName.Substring(0, testName.Length - "_docx".Length);
NListBoxItem item = new NListBoxItem(NStringHelpers.InsertSpacesBeforeUppersAndDigits(testName));
item.Tag = sampleDocxDocuments[i];
testListBox.Items.Add(item);
}
testListBox.Selection.Selected += OnListBoxItemSelected;
testListBox.Selection.SingleSelect(testListBox.Items[1]);
return new NGroupBox("Predefined DOCX documents", testListBox);
}
#endregion
#region Event Handlers
private void OnListBoxItemSelected(NItemEventArgs arg1)
{
if (arg1.TargetNode == null)
return;
// Determine the full name of the selected resource
NEmbeddedResource embeddedResource = (NEmbeddedResource)arg1.Item.Tag;
// Read the stream
if (embeddedResource != null)
{
using (Stream stream = new MemoryStream(embeddedResource.Data))
{
m_RichText.LoadFromStream(stream, NTextFormat.Docx);
}
}
}
#endregion
#region Fields
private NRichTextView m_RichText;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}