First WinForms Ribbon Application - harborsiem/WindowsRibbon GitHub Wiki

First WinForms Ribbon Application

So, let’s see how to use the Ribbon class to add ribbon support to an empty WinForms application.

Step 0 – Download Windows Ribbon for WinForms As I’ve mentioned in previous posts, you can download the code for my ribbon wrapper library along with numerous samples from Github. In this post I’ll review how to create your first, ribbon-enabled WinForms application, the result is the sample application “01-AddingRibbonSupport”, included on the site. You should also download the latest MSI setups from the Releases page. Unpack the msi.zip and install all *.msi files by double clicking. Maybe you get a warning during installation. This is because the msi files are not signed, but safe.

Step 1 – Reference Windows Ribbon for WinForms Create a new C# WinForms application and add a reference to our developed library, Ribbon.dll

(Example based on Visual Studio 2017 or 2019:) In Solution Explorer References: choose -> Add Reference -> Assemblies -> Extensions -> Ribbon.dll

!Note
In newer versions the name of the Ribbon is: Windows Ribbon for .NET

SelectRibbon

Visual Studio Menu: Tool -> Choose Toolbox Items: Select Ribbon with Namespace RibbonLib

ToolBoxItems

ChooseToolBoxItems

Also, add to your main form (form1.cs) the following lines:

using RibbonLib;
using RibbonLib.Interop;

public partial class Form1 : Form
{
    private Ribbon _ribbon = new Ribbon();

!Note
Instead defining “private Ribbon _ribbon ...” you should place a Ribbon with the WinForms Designer with Dock.Top to the Form.

Step 2 – Add ribbon markup XML file Add an empty file named RibbonMarkup.xml to the Visual Studio project with "Properties -> Build Action" = Content. One can also create the RibbonMarkup.xml by the tool RibbonTools. After creating one had to add this file to his project.

Set the file text to the following:

<?xml version='1.0' encoding='utf-8'?>
<Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'>
  <Application.Commands>
  </Application.Commands>
  <Application.Views>
    <Ribbon>
    </Ribbon>
  </Application.Views>
</Application>

Right click on the editor where RibbonMarkup.xml is opened and click properties, now set the Schemas property to: C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\UICC.xsd or a path of a newer SDK version.

Alternative you can do it by Visual Studio Menu: XML -> Schemas...: Select http://schemas.microsoft.com/windows/2009/Ribbon with Filename UICC.xsd (UICC.xsd is in the Windows SDK bin folder). Maybe you have to add this schema first in the dialog "XML Schemas".

Schemas

This will [visual] assist you in the future while editing the ribbon markup file (try Ctrl+Space on the xml editor to see the ribbon markup syntax).

!Note: This is the moment where some of you will discover they didn’t install Windows 7 SDK or a newer Windows SDK, so go ahead and fix it, I’ll wait. You should also install the C++ Tools in Visual Studio, because we need the Linker Link.exe.

Step 3 – Compile markup XML file

Open a Console window at your markup XML file and type RibbonTools RibbonMarkup.xml --build.

This Command calls the Markup compiler UICC.exe, the ResourceCompiler Rc.exe and the Linker Link.exe to build a Resource dll named RibbonMarkup.ribbon and a file RibbonItems.Designer.cs or RibbonItems.Designer.vb.

Another way is to use the GUI program RibbonTools, which you can find in the Windows StartMenu. Now you can open your RibbonMarkup.xml and build the RibbonMarkup.ribbon and a file named RibbonItems.Designer.cs or RibbonItems.Designer.vb.

Explanation: The first program UICC.exe compiles the ribbon markup file to a binary compressed format, along with a small RC file that describes it. The second program Rc.exe creates a native win32 resource file to be attached to the project native resources. The third program Link.exe creates a resource dll from the native win32 resource file.

Step 4 – Add RibbonMarkup.ribbon to the project

Add the files RibbonMarkup.ribbon and RibbonItems.Designer.cs to your project. The RibbonMarkup.ribbon should have the Build Property “Embedded Resource” and RibbonItems.Designer.cs have the Build Property “Compile”.

In Windows Form Designer mark to the Ribbon. Now you have to set in the Properties Page of the Ribbon Control the Property ResourceName to [default_namespace_of_the_project].RibbonMarkup.ribbon.

Step 5 – Enjoy your first Ribbon WinForms application

FirstRibbon

!Note:
If you run your application and don’t see the ribbon, try to enlarge the window size. The windows ribbon has a feature that if the window size is too small, it doesn’t show. Unfortunately, Visual Studio default form size may be too small.

⚠️ **GitHub.com Fallback** ⚠️