Click here to Skip to main content
Click here to Skip to main content

An easy way to add a Ribbon Panel Office 2007 style

By , 18 Apr 2007
 
Prize winner in Competition "Best C# article of Mar 2007"
Screenshot - overview.jpg

Introduction

A picture is worth a thousand words, well it was a really cute work at the end. Before explaining how to add it to your applications, I will show you the main features.

Features of RibbonStyle Namespace

  • RibbonButton: Transparency, Autosizable image, AutoForecolor, AutoInfoForm (see InfoForm, OnBackImage and ClickBackImage).
  • TabPanel: Transparency, BaseColor, BaseColorOn (Highlighted), Caption, Resizable.
  • TabStrip: Has inside:
    1. Tab: With Autowidth, BaseColor, HaloColor and Enable work.
    2. TabStripProffesionalRenderer: Controls the Tab Style (hard to work)
    3. TabStripPage: BaseColor, inherits my RibbonPanel.
    4. TabPageSwitcher: Controls the link between Tab and TabStripPage. Design functionality as the tabcontrol.
  • InfoForm (with Shadow): Depending on Title, Comment, and Image of Info.. Properties of RibbonButton resizes itself.

Using the controls

I hope that if you have understood the Features, the next will be easy for you.

  1. Make a new C# App.
  2. Add all the classes to your app.
  3. Now Rebuild the project.
  4. In the toolbox you will have many new controls:

    Screenshot - toolbox.jpg

  5. Now Add a Windows.Forms.Panel to the Form and dock to the top, adjust it like you want.
  6. Add the TabStrip inside the Panel.
  7. With the TabStripPageSwitcher you can add TabStrip. If you find it difficult to click on it, you can click in the properties window:
  8. Screenshot - tabpageswitcher.jpg

  9. With a TabStrip and some tabs and TabStrip pages, add TabPanels inside the TabStripPages (Check the TabPanel has BackColor.Transparent) . I recommend you to add a few of them to the form and copy and paste inside the tabStripPage (it is easy to dock them later). With the Tabpanels added, dock them to the left.
  10. Now add the RibbonButton inside the TabPanel, adjust its size and its images, copy and paste as you want and change the image. Don't worry about the text colors, they will be processed at runtime.
  11. If everything is ok and if you run it, you will see something like this (Azure Style):

    Screenshot - tabs.jpg

Creating your custom style

As you could see in the demo zip, it is possible to change the colors at runtime. Let's analyze the code. If you look at the Form1 code, there's a method SetStyle:

public void SetStyle(string Name)
{
    Color HaloColor = Color.White;
    switch (Name)
    {
        case "Dark":
        this.BackColor = Color.FromArgb(88,77,69);
        HaloColor = Color.FromArgb(200,200,200);
        SetBase(87,61,53,HaloColor);
    break;...

You find out that you have to change only three colors! I hope you find it useful. The rest are sum or subs from the color components. So to avoid color errors, I recommend taking a look at my other article which has a color selector, only for the basecolor, HaloColor is the brightness over the tabs and the Backcolor is for the form.

Points of Interest

I have to say that I use the base of CustomTabstrip for the part of tabstrip. I was annoyed with the tabcontrol and after looking for something, the best was to inherit from a ToolStrip.

There's a lot of code in the project and I have written this with a lot of effort. If you need an explanation of any part, please ask me. It's .NET 2.0 code I put in a Windows 2000 machine and it works really well in XP and Vista too.

To design a better software, please vote the value of the code for you and if you vote, please tell me the pros and cons.

History

  • 1.0: The first version of the control library.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Juan Pablo G.C.
Software Developer
Spain Spain
Member
I'm Electronic Engineer, I did my end degree project at Astrophysical Institute and Tech Institute. I'm HP Procurve AIS and ASE ,Microsoft 3.5 MCTS
I live in Canary Islands ,developing customized solutions
 
I'm developing with WPF4, SL4 MVVM, MVC3 Razor and WP7 projects, more info at my websites. Improving with Android and IOS.
 
Websites:
MemCards
Mareinsula


Take a look to my blog Juan Pablo G.C.
Mareinsula

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionhow to use in mdi form PinmemberArvindraga19 Oct '12 - 5:18 
sir i want to know how to use in mdi form suppose if i set a ismdicontainer = true.
AnswerRe: how to use in mdi form PinmemberJuan Pablo G.C.19 Oct '12 - 5:47 
GeneralRe: how to use in mdi form PinmemberArvindraga20 Oct '12 - 20:24 
QuestionCreate office 2010 Tabs PinmemberAsif Raza3 Oct '12 - 3:15 
Can You Create office 2010 Tabs and Panels
QuestionCommercial use of Ribbon Panel Control PinmemberVladimir Rech11 Apr '12 - 3:28 
Hi,
 
I'm Working in a software company named Forlogic Software in Brazil.
Today I take a look at your Ribbon Panel Control in Code Project (http://www.codeproject.com/Articles/18449/An-easy-way-to-add-a-Ribbon-Panel-Office-2007-styl) and want to use in a commercial software.
Please, let me know if I can and how.
Contact-me via e-mail in vladimirrech@yahoo.com.br or vladimir.rech@forlogic.net.
 
Thank You and great job!
 
Vladimir Rech
Developer and Project Leader at Forlogic Software Ltda
http://forlogic.net
Questioncool PinmemberMember 871442126 Mar '12 - 4:07 
cool !
GeneralMy vote of 5 Pinmembersportlife27 Feb '12 - 18:04 
Excellent
GeneralMy vote of 5 Pinmemberjraju1142123 Nov '11 - 22:15 
Good
GeneralMy vote of 5 PinmemberSI_SHEN_00125 Sep '11 - 21:22 
it's a good idea
GeneralMy vote of 5 Pinmembervahidmir29 Jul '11 - 19:30 
every thing is Good,thanks a lot
GeneralMy vote of 5 PinmemberSaumitra Kumar Paul31 May '11 - 20:22 
nice effort for a free eye-catchy tool.
GeneralMy vote of 5 Pinmemberhadre11 May '11 - 20:31 
Muy bueno !!
QuestionRight to left layout Pinmembersalimdz200230 Apr '11 - 4:57 
Nice work and exactly what I search to include to my works.
 
When I tried to use your control in RightToLeft application, the tabstrip control take the RightToLeft property well, but the TabStripPage does not, all of its controls still in the left side.
 
You must find a solution to this problem.
 

My vote will be 5/5 then.
 

Thanks
AnswerRe: Right to left layout [modified] Pinmemberbehnam_jan6 Oct '11 - 2:16 
GeneralMy vote of 5 Pinmemberhruday123456711 Feb '11 - 20:30 
Juan really i appreciate your code.and best of luck .
GeneralMy vote of 5 PinmemberMehdi Ghiasi9 Aug '10 - 1:07 
Excellent!
GeneralMy vote of 5 Pinmemberkiumarskahoori30 Jun '10 - 3:14 
very Good tnx
GeneralContent Pinmemberdave5280327 Jun '10 - 5:49 
Do you have any suggestions as to how one goes about adding content to the ribbon window? I see how you open response dialogs, but for all the ribbon tutorials I have looked at I don't find one that explains how you get the actual content in the window. For example Access 2010 starts with a window that lets you select a database, then opens that database in a format that fills the whole area below the Ribbon. It is "like" the ribbon is the MDI parent. Any clues?
GeneralHandling enablig/disabling button Pinmemberlkrfan16 Jun '10 - 10:11 
Hey,
 
I like your control, do you have any idea how to handle enabling/disabling button, I mean visualy with replacing image with disabled one (gray for example). Thanks, Alex
GeneralError when running under .NET 4.0 PinmemberIanlo21 Apr '10 - 7:47 
Hi,
 
Firstly I want to acknowledge your excellent work on this ribbon UI. Its fantastic stuff! Keep up the good work.
 
I am encountering a problem in GlobalHook.cs when running the code under .NET 4.0 - the if (Handle == 0) throw... exception is being raised because the WinApi.SetWindowsHookEx returns 0.
 
In order for the code to continue running, I had to comment out that line as shown..
 
/// Hook
_hHook = WinApi.SetWindowsHookEx(htype, _HookProc, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);

/// Error check
// commented out when compiling under .NET 4.0 so as to prevent exception from being raised because WinApi.SetWindowsHookEx returns 0 under .NET 4.0
//if (Handle == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
 
Any idea why this is happenning? Thanks!
 
Ian
Generaloutlook sidebar PinmemberMember 31108197 Mar '10 - 5:57 
if you wanna own sidebar in outlook, you can access http://www.olassistant.com[^]
GeneralPRoblem i can't import it to VS 2008 [modified] PinmemberMichalss7 Jan '10 - 21:24 
Hello,
im having trouble to import it to my Toolbox in VS2008 team, getting this error and o dont know why ?
Error "Unable to found assebmly TabControlLibrary Version=1........ Culture=neutral...."
 
Any help pls ?
 
Thx
 
modified on Saturday, January 9, 2010 4:18 AM

GeneralRe: PRoblem i can import it to VS 2008 PinmemberMichalss7 Jan '10 - 21:38 
GeneralRe: PRoblem i can import it to VS 2008 PinmemberJaime Stuardo8 Jan '10 - 15:14 
GeneralRe: PRoblem i can import it to VS 2008 PinmemberMichalss8 Jan '10 - 22:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 18 Apr 2007
Article Copyright 2007 by Juan Pablo G.C.
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid