First WinForms Ribbon Application - harborsiem/WinForms-Ribbon GitHub Wiki

First WinForms Ribbon Application

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

Step 0 – Download RibbonFramework 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.

Step 1 – Reference RibbonFramework for WinForms Create a new C# .NET WinForms application (Minimum .NET version = 8.0). Go to the Solution Explorer in Visual Studio (2022), select Dependencies and manage NuGet packages by right clicking. Browse with the name RibbonFramework.CCW and install this package. Now the library RibbonFramework is present in your project. You can also see the class RibbonFramework => RibbonStrip in the designer toolbox. Place the RibbonStrip 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 RibbonTools64. 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 RibbonTools64 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 RibbonTools64, 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 RibbonStrip. Now you have to set in the Properties page of the RibbonStrip control the Property MarkupResource 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** ⚠️