About me
About Me
Home Articles Code Projects Contact
 
 
(Category) > (Language)
 

Embedding the Ribbon on the Non-Client Area

 

This article explain how to embed the Professional Ribbon on the non-client area of the window. You may first download the latest release of the ribbon (release 0.4) needed.

Sure it looks great and it's quite easy to make it work.

As you may see in the pictures above, it renders glass on Vista with Aero enabled and he whole form in any other case.

There are two ways to achieve it:

  • Inherit from RibbonForm
  • Implement IRibbonForm

Both options are really simple. Well the first one is simpler :)

 

Option 1: Inherit from RibbonForm

Inherit the form where you will host the ribbon from Sytem.Windows.Forms.RibbonForm

    public partial class Form1 : RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

And now this form will host the ribbon embedded on the non-client area.

Option 2: Implementing IRibbonForm

I know that sometimes you just can't inherit from RibbonForm since you may have to inherit from other form by any means.

The solution is to implement the Sytem.Windows.Forms.IRibbonForm interface and bypassing some methods to a classs named RibbonHelper.

In fact just make sure your form accomplishes to have this code at least:

using System.Windows.Forms.RibbonHelpers;

    public class MyForm
        : Form, IRibbonForm
    {
        private RibbonFormHelper _helper;

        public RibbonForm()
        {
            if (WinApi.IsWindows && !WinApi.IsGlassEnabled)
            {
                SetStyle(ControlStyles.ResizeRedraw, true);
                SetStyle(ControlStyles.Opaque, WinApi.IsGlassEnabled);
                SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                DoubleBuffered = true;
            }
            _helper = new RibbonFormHelper(this);
        }

        protected override void WndProc(ref Message m)
        {
            if (!Helper.WndProc(ref m))
            {
                base.WndProc(ref m);
            }
        }

        public RibbonFormHelper Helper
        {
            get { return _helper; }
        }

    }
  • The code on the constructor initializes necessary styles to make the form look good on repainting and stuff like that.
  • The code on WndProc passes the WndProc to the Helper to make the ribbon able to fit the non-client area.
  • The Helper property is implemented because of IRibbonForm

Note: If any of the code above is missing the results can become messy.

Important things to consider

  • When embedding the Ribbon on the non-client area, some graphic glitches are yet to be solved, but it works pretty fine for now.

  • The method explanied on my Non-client area article is used to embed the Ribbon, so you may remember that the actual non-client area of the form disappears, is only an illusion. The pixel at (0,0) of the form is the absolute top and left most of the form, including the borders and margins.

  • The Form will be themed even when the windows themes are turned off.

  • If you disable Aero when the app is running, the form is not capable of switching, graphical glitches will be visible.

Stay tunned

-- Your firend, J

Edit
Created: 2009-04-30 17:57:11
Modified: 2009-06-25 11:34:37
Rate this Article: (Current rating is 3 out of 5)
 

Article messages

jens > test
Barzille > XP Title Bar Issues ever to be fixed?
Omar from Argentina-Jujuy > Solution for VB.Net
CroBasic > this is great....
J8 > I mean it doesn't work in designer view.
J8 > VB NET VERSION PLEASE!!!!!!!!!!!!!!!!!
wardsi > Name property
oliver cortinas > Can't load with visual studio 2008
Eiríkur Fannar Torfason > Non-aero redraw issues
vikram kumar chaurasiya > C# windows application
lakshman > multiple
Henrique > MDI Bug
Cosmic > For VB .NET
Joe > RightToLeftLayout not supported ?!
Dirk Helbig > Please add a strong name and make it CLS-compliant
Dirk Helbig > Please provide more XML-documentation
Juan Carlos > visible buttons
Ashwin Hegde > About Ribbon
SeraTJ > Possible fix for redraw
Navid > Ribbon in Visual basic 2008 .net
sean > Bug when double click on ribbon form tile (non-cli
Jax > Embedding in VB.Net
Edward111 > how to add caption's form
Helmut > Ribbon in a User Control
AngelHeart > bugs on display Ribbon
AlexS > Invalidate on MouseMove :) a bit processor intensi
AlexS > Windows XP loose focus problem
pimvdb > Great! (but some spelling mistakes)
jus > Rendering problems with ElementHost control on for
alejandro > MDI
Jamie > Please
RipsWare > vb.net version
MaX > Non-Client Area in a MDI Container Window

Post message
Your name: Your e-mail:
Subject:
Write visual code on the box:
*All fields are required
Rate this Article: (Current rating is 3 out of 5)

RSS