Start Menu, ToolBar and Shortcuts Creation in C# RibbonBar
KetticRibbonBar is a Windows Forms component used to build user interface of ribbon bar by C# developers. By using this control, the UI designers are able to create a Quick Access Toolbar to add functionalities on a KetticRibbonBar, and even create a start menu to add many more functionalities. Furthermore, this control allows the users to build keyboard shortcuts to some of the functionalities. The following are the detailed C# tutorial for creating Start Menu, Quick Access Toolbar, and keyboard shortcuts.
How to Create Quick Access Toolbar in RibbonBar in C#
- Before we create a quick access toolbar, we need to drag and drop the ImageList control to the form first. And open the Images Collection Editor, add the desired images to the ImageList or use the existing images.
- Create a KetticRibbonBarForm in your C# Windows project. This can be done through modifying the base C# class of a standard KetticRibbonBarForm or using the Add New Item dialog
- Choose the KetticRibbonBar control, select the imageList1 option from the drop down menu of ImageList property
- Add new tabs to the KetticRibbonBar control by clicking Add New Tab and type text Write to the Tab.
- Now we can add Items to the quick access toolbar. Open the properties window of the KetticRibbonBar and locate the QuickAccessToolbarItems property. In the Collection Editor, click drop down arrow on the Add button to add items, one CommandBarSeparator and two KetticButtonElements.
- In the KetticElement Collection Editor, customize the properties of button element by clicking ketticButtonElement1 and ketticButtonElement2 in the Members list. Set the DisplayStyle property to Image in button element1, and then add an image through the ImageIndex property, set the text of the element to Open File. Similarly, set an icon to the ketticButtonElement2.
- Add a RichTextBox by drag and drop a RichTextBox control on the form. In the Smart Tag, execute the Dock in parent container action.
- Add the C# code below to the code window of the form. The C# code connects the RibbonBar control to the methods that will run the quick access menu item when the users clicking the button.
- Run the project and add text to the RichTextBox control, highlight the text and click the Bold quick access menu item to toggle the bold property on and off. Use the File Open icon to open a .txt file or an .rtf file for the RichTextBox.
Create Start Menu using C# RibbonBar Crontrol
- To create a start menu, we need to add a start button first. This can be done by using the StartButtonImage property of the KetticRibbonBar control. In the editor of the StartButtonImage property, choose the Local Resource option in the Select Resource dialog box and import an image through the Import button.
- In the second step, we shall add Items to the Start Menu by using the StartMenuItems property. In the Collection Editor of this property, add two KetticMenuItem items and one KetticMenuSeparatorItem item by choosing the item from the drop down arrow list of the Add button.
- Set the DisplayStyle property of the ketticMenuItem1 to Image and the Text property of this item to Open File. Set the suitable image of the File Open item on the quick access menu via the ImageIndex property.
- Set the DisplayStyle property of the ketticMenuItem2 to Text and the Text property of this item to Recent Files. Here, we will add a sub menu to the ketticMenuItem2 via the Items property. In the Collection Editor of this property, add four KetticMenuItem items and set the DisplayStyle property to Text to show the most recently used four files.
- After that, we shall create application settings to keep track of the four files that were most currently used by the users. In the Properties of the menu, click the Settings tab to open the Application Settings property page, and then tab to the next cell to create a new row in the Name field of the first row type File1.
- Modify the exiting C# code by replacing the OpenFile method with the C# code below. Add the File Open button Click event of ketticMenuItem1 to the event handler. This is achieved by opening the Properties window of ketticMenuItem1 of KetticRibbonBar control, clicking the Events icon, locating the Click event and choosing ketticButtonElement1_Click.
- Add the C# code to the Start Menu Items. The C# code connects these methods to the RibbonBar control events. Open the Properties window of the control, select ketticMenuItem1 and click the Events icon. Locate the Click event and choose ketticMenuItem2_DropDownOpening.
- Set the Click events to OpenfromMRU for ketticMenuItem3, ketticMenuItem4, and ketticMenuItem5
- Run the Windows Forms project to check the results
Create Keyboard Shortcuts for RibbonBar in C# code
KetticRibbonBar control for Windows Forms allows the users to build keyboard shortcuts to some of the functionalities. The following are the C# code that demonstrates how to add shortcuts to KetticMenuItem.
ketticMenuItem1.Shortcuts.Add(new Kettic.WinControls.KetticShortcut(Keys.Control, Keys.O));
ketticMenuItem2.Shortcuts.Add(new Kettic.WinControls.KetticShortcut(Keys.Control, Keys.B));