Using Ribbon Control with Windows Forms: What I Learnt Today?

If you like this post, please visit our sponsors above. Thanks!

Recently I have been exploring the use of Ribbon Control. Yesterday, I posted a tutorial on its use with Windows Workflow Foundation. However, I am far more comfortable developing applications with Windows Forms compared to WPF. So, I searched for Ribbon Control for Windows Forms. Although I found an open source version here, there was no associated tutorial. So I decided to write one. In this tutorial I will explain how to create a simple windows forms application with a Ribbon Control and how to add buttons.

If you need the basic concepts about Ribbon Control, read the first part of my previous post.

1. Download the Ribbon Control binaries here.

2. Create a Windows Forms Visual Studio Project.

3. Add reference to the downloaded System.Windows.Forms.Ribbon.dll

4. Declare a System.Windows.Forms.Ribbon reference in Designer.cs file of your form and create an object (you also need to add some more supporting code). Be sure to include System.Windows.Forms to your code. Your .Designer.cs file should look somewhat like this;

using System.Windows.Forms;

 

namespace DMProject

{

    partial class Form1

    {

        /// <summary>

        /// Required designer variable.

        /// </summary>

        private System.ComponentModel.IContainer components = null;

        private System.Windows.Forms.Ribbon ribbon1 = null;

 

        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }

 

        #region Windows Form Designer generated code

 

        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

        {

            this.ribbon1 = new System.Windows.Forms.Ribbon();

            this.SuspendLayout();

            // 

            // ribbon1

            // 

            

            // 

            // Form1

            // 

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(284, 262);

            this.Controls.Add(this.ribbon1);

            this.Name = "Form1";

            this.Text = "Form1";

            this.ResumeLayout(false);

 

        }

 

        #endregion

    }

}

 

Your Windows Form Should look like this;

image

From this point onward, adding controls to the ribbon should be easy.

5. To add a tab to your ribbon control, click ‘Add Tab’. I have added three tabs; Home, Data Manipulation and Visualization. As with any control, you can change the properties of the tabs using the properties grid.

image

You can now compile and run the application, it would look like the screenshot above.

6. The next step is to add a panel to contain the buttons. To do this, click the ‘Add Panel’ button. Change the properties of the panels as desired.

7. Once the panels have been created, click a panel. The property grid shows options for the panel. Besides ‘Add Button’, these options include ‘Add Button List’, ‘Add Item Group’, ‘Add Separator’ etc. Click the ‘Add Button’ command. A button is created. You can use the property grid to set the text, tool tip and image for the button.

To add images to these buttons, you first have add the PNG images to your project resources. To do this, right click on your project and click Properties. In the resources tab, select ‘Add Existing File’ and browse for your PNG icons.

image

Congratulations! you have successfully added a ribbon control to your Windows Forms Application. You are good to go!

image

If you like this post, please visit our sponsors blow. Thanks!

14 Responses to “Using Ribbon Control with Windows Forms: What I Learnt Today?”

  1. Kasun says:

    after changing design.cs i am getting “could not load type System.Windows.Forms.Ribbon from assembly System.Windows.Forms.Ribbon, version = 1.0.0.0, culture = neutral, publicKeyTiken = null because the method add_orbClicked has no implemented (no RVA)

  2. ji seung Hoon says:

    Hi!..

  3. Srinivas says:

    Hello Tayyab
    in the first image shown, how can i put the control box controls (minimize, maximize and exit) as a part of ribbon? like in any office application

    same goes with the text in the ribbon bar

    thank is advance

  4. Alex says:

    How can I get the ribbon to be displayed on the non-client area?
    Your illustration shows the ribbon in the client area of the form which is not what we have with Microsoft’s version.

    See Word/Excel/Access 2007 for what I mean.

  5. Bruno Laurinec says:

    Hi Alex,

    change your designer code to be like:

    C#:
    public partial class Form1 : RibbonForm

    VB.NET:
    Partial Class Form1
    Inherits RibbonForm
    ….
    ….
    ….
    End Class

  6. Menth says:

    Thanks! I was looking solution for painting to non client area and found it here! First I couldnt believe that it would be that easy! :)

  7. memo says:

    It doesn’t work at all..

  8. Mick says:

    I can’t use it with .net framework 4.0.
    Any solution to have it worked?

  9. Pascal says:

    after writing in the designer i get the following:
    could not load type “System.Windows.Forms.RibbonForm” from assembly “System.Windows.Forms.Ribbon, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null” because the method “.ctor” has no implementation (no RVA)
    what do i have to do??

  10. Meng Thona says:

    unlucky it not support my Unicode (Khmer).
    if have solution please help.

  11. Zehan says:

    I tried to use the Ribbon and it works fine. I made a MDI form and added the ribbon to it and created buttons. I opened another form by clicking a button in the ribbon. I t got opened.
    But the only problem is that when i try to close the opened form or maximize it the application gets stuck for a while and only performs the action!!!

    Any idea why this happens???

  12. Ubaid says:

    I’m facing the same problem as Zehan above, is there any solution to this. besides this your control is awsome and amazing. thanks much!

    ubaid

  13. xcesco says:

    @Zehan – I had the same problem. I solved it removing hooks.

  14. JanO says:

    Is there any way of removing the quickaccesstoolbar completly?
    If its set QuickAccessVisible to false its still shown.. :-p

Leave a Reply