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.
Changing the Ribbon Item's Text
In order to change the text of a RibbonItem ( TXText
╰ Windows.Forms.Ribbon Namespace
╰ RibbonGroup Class
╰ RibbonItems Property
Gets a collection of all items contained in this group. ), the TXText
╰ Windows.Forms.Ribbon Namespace
╰ RibbonFormattingTab Class
╰ FindItem Method
Finds a control that has the provided RibbonFormattingTab.RibbonItem identifier. can be used to retrieve the RibbonItem. Using the TXText
╰ Windows.Forms.Ribbon Namespace
╰ RibbonButton Class
╰ Text Property
Overridden. , 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 TXText
╰ Windows.Forms.Ribbon Namespace
╰ RibbonGroup Class
The RibbonGroup class represents a logical group of controls as they appear on a RibbonTab and is the base class of the HorizontalRibbonGroup 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!