Exploring the CodeFluent Runtime: The Ribbon Control
Now, the free CodeFluent Runtime Client Library that we, at SoftFluent, provide, will allow us to easily integrate a similar control in your Windows Forms applications. First of all, just take a look at the following screenshot of this RibbonControl schema:
The RibbonControl consists of different tabs called RibbonTab (crazy huh?). Each tab (as ‘Home’ and ‘View’ above) can include one or several groups of controls of RibbonPanel type (as ‘Clipboard’, ‘Font’, ‘Paragraph’, and ‘Insert’ above). Each panel consists of a list of RibbonItems objects (RibbonItem is not a control, it’s just a wrapper object). Each RibbonItem can embed standard controls such as a Button or a DropDownList.
Now, I’m going to explain how to create the RibbonControl introduced above programmatically (as of today, we don’t provide a cool Visual Studio designer integration, so this is in fact the only way to use this control…)
Add a RibbonControl in a Windows form (Winforms technology) :
The first easy step is to add a RibbonControl, in the same way that you would add a button to a form. The RibbonControl inherits from the Control class:
var ribbonControl1 = new CodeFluent.Runtime.Design.RibbonControl(); this.Controls.Add(ribbonControl1);
Add RibbonTabs to RibbonControl:
var homeTab = new CodeFluent.Runtime.Design.RibbonTab("Home"); var viewTab = new CodeFluent.Runtime.Design.RibbonTab("View"); ribbonControl1.Tabs.Add(homeTab); ribbonControl1.Tabs.Add(viewTab);
Add RibbonPanel to RibbonTab:
var clipBoardPanel = new CodeFluent.Runtime.Design.RibbonPanel("Clipboard"); var fontPanel = new CodeFluent.Runtime.Design.RibbonPanel("Font"); var paragraphPanel = new CodeFluent.Runtime.Design.RibbonPanel("Paragraph"); var insertPanel = new CodeFluent.Runtime.Design.RibbonPanel("Insert"); homeTab.Panels.Add(clipBoardPanel); homeTab.Panels.Add(fontPanel); homeTab.Panels.Add(paragraphPanel); homeTab.Panels.Add(insertPanel);
Add RibbonItem to RibbonPanel:
Finally, we add some standard controls to the RibbonPanel :
var copyButton = new CodeFluent.Runtime.Design.RibbonButton("Copy"); copyButton.Mode = CodeFluent.Runtime.Design.RibbonItemMode.Icon; copyButton.IconIndex = 0; var pasteButton = new CodeFluent.Runtime.Design.RibbonButton("Paste"); pasteButton.Mode = CodeFluent.Runtime.Design.RibbonItemMode.Icon; var pasteOptionDdl = new CodeFluent.Runtime.Design.RibbonDropDownList("Paste options"); pasteOptionDdl.Items.Add(new CodeFluent.Runtime.Design.RibbonDropDownItem("Paste")); pasteOptionDdl.Items.Add(new CodeFluent.Runtime.Design.RibbonDropDownItem("Paste special")); clipBoardPanel.Items.Add(copyButton); clipBoardPanel.Items.Add(pasteButton); clipBoardPanel.Items.Add(pasteOptionDdl);
Just compile your code to get the desired result :
RibbonControl provides an ImageList property that can’store all the icons we need (such as ‘Copy’ / ‘Paste’ buttons here). So, for example, we can add two images to our Windows Forms project and to the image collection (ImageList) of the RibbonControl:
ribbonControl1.ImageList = new ImageList(); ribbonControl1.ImageList.ImageSize = new System.Drawing.Size(32, 32); ribbonControl1.ImageList.Images.Add(Image.FromFile(@"Images\copyButtonIcon.png")); ribbonControl1.ImageList.Images.Add(Image.FromFile(@"Images\pasteButtonIcon.png"));
To assign one of these icons to RibbonItem, simply assign the RibbonItem’s IconIndex property, which corresponds to the index of an image in this list:
pasteButton.IconIndex = 1;
Note that you can also resize all images in the collection this way :
ribbonControl1.ImageList.ImageSize = new System.Drawing.Size(32, 32);
In order to handle different sizes of icons, the RibbonControl exposes a second image collection, the SmallImageList. To assign an icon of this collection, just use the SmallIconIndex property.
Convenient and easy, don’t you think ?
Add RibbonControl in WPF application
Since WPF day one, it’s possible to host Windows Forms controls in your WPF application. So, if you need to use the RibbonControl in xaml, check out this article.
There are expensive ribbon controls out on the market offering much more features than this one. Its main advantage is it’s simple and … free. This control is provided 100% free of charge. Its license is tied to the CodeFluent Runtime Client license (which basically allows you to do anything with it…). The support is provided on a best-effort basis, so if you have any questions about this control or our products, feel free to visit the SoftFluent forum.
The R&D team.