Ribbon Customization Example for Blazor

Nevron NOV RichTextEditor for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor RichTextEditor examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Ribbon Customization Example for Blazor Description

This example demonstrates how to customize the NOV rich text ribbon.


Ribbon Customization Example

C# Ribbon Customization Example Code for Nevron RichTextEditor for Blazor
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.Commands;
using Nevron.Nov.Text.UI;
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 - NRibbonCustomizationExample";

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

			// Populate the rich text
			PopulateRichText();

			// Add the custom command action to the rich text view's commander
			m_RichText.Commander.Add(new CustomCommandAction());

			m_RibbonBuilder = new NRichTextRibbonBuilder();

			// Rename the "Home" ribbon tab page
			NRibbonTabPageBuilder homeTabBuilder = m_RibbonBuilder.TabPageBuilders[NRichTextRibbonBuilder.TabPageHomeName];
			homeTabBuilder.Name = "Start";

			// Rename the "Font" ribbon group of the "Home" tab page
			NRibbonGroupBuilder fontGroupBuilder = homeTabBuilder.RibbonGroupBuilders[NHomeTabPageBuilder.GroupFontName];
			fontGroupBuilder.Name = "Text";

			// Remove the "Clipboard" ribbon group of the "Home" tab page
			homeTabBuilder.RibbonGroupBuilders.Remove(NHomeTabPageBuilder.GroupClipboardName);

			// Insert the custom ribbon group at the beginning of the home tab page
			homeTabBuilder.RibbonGroupBuilders.Insert(0, new CustomRibbonGroup());

			// Create the ribbon commanding UI
			NCommandUIHolder richTextViewWithRibbon = m_RibbonBuilder.CreateUI(m_RichText);

			// Remove the Open command from the File menu and the page number command from the status bar
			richTextViewWithRibbon.RemoveCommands(NRichTextView.OpenCommand, NRichTextView.PageNumberStatusBarCommand);

			return richTextViewWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			return null;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to customize the NOV rich text ribbon.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Ribbon via Code", "https://www.nevron.com/docs/openvision/rich-text-ribbon-via-code.html"), ("Rich Text Commanding Overview", "https://www.nevron.com/docs/openvision/rich-text-commanding-overview.html"), }; } private void PopulateRichText() { NSection section = new NSection(); m_RichText.Content.Sections.Add(section); section.Blocks.Add(GetDescriptionBlock("Ribbon Customization", "This example demonstrates how to customize the NOV rich text ribbon.", 1)); } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NRichTextView m_RichText; private NRichTextRibbonBuilder m_RibbonBuilder; #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; } /// /// Gets a paragraph with title formatting /// /// /// private static NParagraph GetTitleParagraph(string text, int level) { NColor color = NColor.Black; NParagraph paragraph = GetTitleParagraphNoBorder(text, level); paragraph.HorizontalAlignment = ENAlign.Left; paragraph.Border = CreateLeftTagBorder(color); paragraph.BorderThickness = DefaultBorderThickness; return paragraph; } private static NGroupBlock GetNoteBlock(string text, int level) { NColor color = NColor.Red; NParagraph paragraph = GetTitleParagraphNoBorder("Note", level); NGroupBlock groupBlock = new NGroupBlock(); groupBlock.ClearMode = ENClearMode.All; groupBlock.Blocks.Add(paragraph); groupBlock.Blocks.Add(GetDescriptionParagraph(text)); groupBlock.Border = CreateLeftTagBorder(color); groupBlock.BorderThickness = DefaultBorderThickness; return groupBlock; } 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; } private static NParagraph GetLoremIpsumParagraph() { return new NParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum placerat in tortor nec tincidunt. Sed sagittis in sem ac auctor. Donec scelerisque molestie eros, a dictum leo fringilla eu. Vivamus porta urna non ullamcorper commodo. Nulla posuere sodales pellentesque. Donec a erat et tortor viverra euismod non et erat. Donec dictum ante eu mauris porta, eget suscipit mi ultrices. Nunc convallis adipiscing ligula, non pharetra dolor egestas at. Etiam in condimentum sapien. Praesent sagittis pulvinar metus, a posuere mauris aliquam eget."); } #endregion #region Constants private static readonly NMargins DefaultBorderThickness = new NMargins(5.0, 0.0, 0.0, 0.0); public static readonly NCommand CustomCommand = NCommand.Create(typeof(Nevron.Nov.Examples.Text.NRibbonCustomizationExample), "CustomCommand", "Custom Command"); #endregion #region Nested Types public class CustomRibbonGroup : NRibbonGroupBuilder { public CustomRibbonGroup() : base("Custom Group", Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABsElEQVR4AYWTQ7BjQRSGZz3cjM04Y9u2bdu2bdu29bx83jxzvI79z+munDiVW/Vd/Lf/g0aF0MvyeUJT4ipRTsDLb+ImoQ4zhJifEYjBp2jmfAJWAsmTYP/mN9m+SE08WfsVar7PZuPHcajfRI2M68NFEGn6+3wM6jZSovTRyMAgH9jcgDM5v0/E5+ODUbOBCgeX9oAnfiLccRNxf1c/qV3Z1Ed+B7SjFQHOsiAyplHmSjUUuLZZDoYMemKw1F4eHAjX96AAt7l3MIifIDOZP/k1D5kubuxDCcazxvwTAZyBoouyImUykDCJmMjISeTyA+EAbMbjvf1xaFlP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC"))) { } protected override void AddRibbonGroupItems(NRibbonGroupItemCollection items) { // Add the copy command items.Add(CreateRibbonButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAA10lEQVR4Ae2WsQ3CMBBFswEd4zCX70oGoKLzFqG8EWiZx4cd4e5H4QvrFKF86TWRi6f/r8i0m6SUrpWZ4Kaqp5ECs7tvUkpZBMxsFpF7lwgXcHcgESzASRACl/RAQIEu0W4ipIFGzhkeZpAAhhfgJwgS2GDiM14g5+z1PcNTVc/8BIDPW/8mpZRFwMxcRF5Qgm+AF2jBEnECQGLQBPUbBAl0iXYTIQ20rB1smEBvotNbCZlgJfEN/LcAngADBPh/wvEN8NmJAD/BUIFjgmOCQ8Aq/gM27SVvkCjJreFW3swAAAAASUVORK5CYII=")), Nevron.Nov.Presentation.NResources.Image_Edit_Copy_svg, NRichTextView.CopyCommand)); // Add the custom command items.Add(CreateRibbonButton(Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAADXklEQVR4AcWWA7A8RxDGY5YrxWf7HZ5t29jb2LbNv+24HNs531WlFNsuKzx/6d7shbs7t49b9TvOTH/T0/PNHGbm+e01qYa4mXiW+ID4QeV94mniBsJ+2Eo/odelLTQwTBANvSbdvezANNDVBJbJBUsN/jGBFeKtlAPH3fKJ1CFGYIX5OepyHCkUoBc86pSQcDuEgeLUJuZy6IoQBf9cqyMPGDg4ht1X9QJefRHwyXj4lj68uG0ECY/D1HJwpd+o1SHE769KyCm0IKvAgqc2DiOmkYmoS8IbB8eRkW9Bel4lfnhyFuHXUyxM+E85iv/Qm/0LW0dQVGZFpcWO8xZaeKb/a8eZueWcDpRX2lBaYcMDN/chbrBk/xJASvcarekDN/Upg1qsdkz0NQB+WTP958y1KCJZxIaLuwD9ZeDM3vXPtYcenO7H7h5CSbkNlSTglIlm3QxcdVo7Kiw2lJHYvVf3GtWBQjJ4u1EjXscfn5pFBq1rQakVe6/RHpiFcn3kFVmVWnn7wUlEnMKtaWMBGwWNaHY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lP7FrYHTvmS7B7UQ+cWNULj/f0o5bCA+Tyh8jSTKFGU4UGzZXBNCOtWm2FrCYgwB8R4DQL4ue2ud3QpLkGOp0uiGYUZM6YDkDipMAAN0WAOgQYN5XYv0crNGyqhoJMCpUGjZqp0am9HuaP42H9EtRCC94LN1m0EkiahDeHB2LNjC5YOaUzHu3uL6uzBZtfhe7G7KDV+M4rEHH2i0KPQlAlMXga60TW8U5sHuEkXEQBcYFoGDr+P5RkQoMvtntjAAAAAElFTkSuQmCC")), CustomCommand)); } } public class CustomCommandAction : NTextCommandAction { #region Constructors /// /// Default constructor. /// public CustomCommandAction() { } /// /// Static constructor. /// static CustomCommandAction() { CustomCommandActionSchema = NSchema.Create(typeof(CustomCommandAction), NTextCommandAction.NTextCommandActionSchema); } #endregion #region Public Overrides /// /// Gets the command associated with this command action. /// /// public override NCommand GetCommand() { return CustomCommand; } /// /// Executes the command action. /// /// /// public override void Execute(NNode target, object parameter) { INRichTextView richTextView = GetRichTextView(target); NMessageBox.Show("Rich Text Custom Command executed!", "Custom Command", ENMessageBoxButtons.OK, ENMessageBoxIcon.Information); } #endregion #region Schema /// /// Schema associated with CustomCommandAction. /// public static readonly NSchema CustomCommandActionSchema; #endregion } #endregion } }

Download a fully functional C# (.cs) Ribbon Customization Example for Blazor Solution