Products Technologies Demo Docs Blog Support Company

Customizing the Windows Forms Ribbon

TX Text Control .NET for Windows Forms is shipped with a fully-featured, customizable and programmable Ribbon Bar with pre-configured Ribbon Tabs.

Customizing the Windows Forms Ribbon

TX Text Control .NET for Windows Forms is shipped with a fully-featured, customizable and programmable Ribbon Bar with pre-configured Ribbon Tabs for the most typical applications of TX Text Control.

TX Text Control Ribbon

Changing the Ribbon Item's Text

In order to change the text of a RibbonItem (TXTextControl.Windows.Forms.Ribbon.RibbonGroup.RibbonItems property), the TXTextControl.Windows.Forms.Ribbon.RibbonFormattingTab.FindItem method can be used to retrieve the RibbonItem. Using the TXTextControl.Windows.Forms.Ribbon.RibbonButton.Text property, the text of the button can be changed:

RibbonSplitButton ribbonItem = (RibbonSplitButton)ribbonFormattingTab1.FindItem(
        RibbonFormattingTab.RibbonItem.TXITEM_Paste);

ribbonItem.Text = "New Text";

Adding Events to Ribbon Items

It is possible to attach additional events to existing ribbon buttons. The following code adds a click event to the Paste button:

RibbonSplitButton ribbonItem = (RibbonSplitButton)ribbonFormattingTab1.FindItem(
        RibbonFormattingTab.RibbonItem.TXITEM_Paste);

ribbonItem.ButtonClick += RibbonItem_ButtonClick;

Removing Ribbon Items

The following code removes a ribbon button from the parent container, a TXTextControl.Windows.Forms.Ribbon.RibbonGroup class:

RibbonSplitButton ribbonItem = (RibbonSplitButton)ribbonFormattingTab1.FindItem(
        RibbonFormattingTab.RibbonItem.TXITEM_Paste);

if(ribbonItem.ParentCollection != null)
        ribbonItem.ParentCollection.Remove(ribbonItem);

Removing Ribbon Groups

The next code snipped removes a complete ribbon groug; in this case, the Font ribbon group:

foreach (RibbonGroup group in ribbonFormattingTab1.RibbonGroups)
{
    if (group.Name == "TXITEM_FontGroup")
    {
        ribbonFormattingTab1.RibbonGroups.Remove(group);
        break;
    }
}

Removing Ribbon Tabs

Complete ribbon tabs can be removed using the Controls property of the Windows.Forms.Ribbon.Ribbon control:

ribbon1.Controls.Remove(ribbonInsertTab1);

Creating New Ribbon Tabs

The following code creates a complete new Windows.Forms.Ribbon.RibbonTab with a new Windows.Forms.Ribbon.RibbonGroup. Additionally, a new Windows.Forms.Ribbon.RibbonButton is created and added to the created ribbon group. Finally, the ribbon tab is added to the Controls collection of the ribbon control and the selected tab is specified using the SelectedIndex property:

// create a new RibbonTab control and set the text (tab title)
RibbonTab myRibbonTab = new RibbonTab();
myRibbonTab.Text = "MyRibbonTab";

// create a new RibbonGroup
RibbonGroup myRibbonGroup = new RibbonGroup() { Text = "My Group" };

// make the dialog launcher icon invisible
myRibbonGroup.DialogBoxLauncher.Visible = false;

// add the new RibbonGroup to the RibbonGroup collection
// of the newly created RibbonTab
myRibbonTab.RibbonGroups.Add(myRibbonGroup);

// create a new RibbonButton
RibbonButton rbtnClickMe = new RibbonButton()
{
    Text = "Click me!",
    IsAddToQuickAccessToolbarEnabled = true,
};

// set some properties of the button and attach a "Click" event
rbtnClickMe.ToolTip.Title = "Tooltip Title";
rbtnClickMe.ToolTip.Description = "Tooltip Description";
rbtnClickMe.DisplayMode = IconTextRelation.LargeIconLabeled;
rbtnClickMe.LargeIcon = Image.FromFile("previewclose.png");
rbtnClickMe.Click += RbtnClickMe_Click;
rbtnClickMe.BackColor = Color.LawnGreen;

// add the button to the RibbonGroup
myRibbonGroup.RibbonItems.Add(rbtnClickMe);

// add the newly created RibbonTab to the Ribbon control
ribbon1.Controls.Add(myRibbonTab);

// set the selected tab to the new RibbonTab
ribbon1.SelectedIndex = ribbon1.TabCount - 1;

Happy coding!

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.Windows.Forms.Ribbon.RibbonButton.Text Property
  • TXTextControl.Windows.Forms.Ribbon.RibbonFormattingTab.FindItem Method
  • TXTextControl.Windows.Forms.Ribbon.RibbonGroup Class
  • TXTextControl.Windows.Forms.Ribbon.RibbonGroup.RibbonItems Property

Windows Forms

Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.

See Windows Forms products

Related Posts

Windows Forms.NET 8Ribbon

Getting Started: Creating a .NET 8 Windows Forms Ribbon Application with…

This article shows how to create a Windows Forms application with a Ribbon and a Sidebar using TX Text Control .NET for Windows Forms. The Sidebar is a control that can be used to create a…


Windows FormsMail MergeRibbon

Windows Forms Ribbon: Displaying User-Friendly Merge Field Names

Database column names can be complex and confusing to end-users. This article shows how to display user-friendly names in the ribbon.


ReportingWindows FormsRibbon

Using the Reporting RibbonTab

The Reporting RibbonTab provides all features to create out-of-the-box reporting applications.


Windows FormsReleaseRibbon

Version X14: Customizing the Text Control Ribbon Control

TX Text Control X14 (24.0) comes with a fully-customizable, programmable Ribbon control. Pre-configured RibbonTabs can be used to create typical TX Text Control applications without writing a…


Windows FormsReleaseRibbon

Adding Elements to the Ribbon QuickAccessToolbar

Version X14 implements a new Ribbon Control with the typical ribbon functionality and it comes with pre-configured ribbon tabs for the most typical tasks of TX Text Control. The Quick Access…