Click here to Skip to main content
15,896,434 members
Articles / Programming Languages / C#
Article

Office 2007 ToolStrip Renderer

Rate me:
Please Sign up or sign in to vote.
4.90/5 (73 votes)
6 Dec 20062 min read 308K   5.9K   211   46
Use a custom tool strip renderer to achieve the Office 2007 look and feel.

Sample Image

Introduction

With the release of Office 2007, you will want to update your applications with the latest look and feel. With .NET 2.0, this is a simple process as you just need to use this custom renderer for the ToolStrip manager. Assign the custom renderer to the ToolStripManager.Renderer property, and it will customize the appearance of all ToolStrip, MenuStrip, StatusStrip, and ContextMenuStrip instances in your application.

Using the Custom Renderer

To make use of the custom renderer, you need to hook into the Load event of your Form. Just double click the form at design time to have the event handler for the Load event auto generated. Then, you need to add just this single line of code...

C#
private void Form1_Load(object sender, EventArgs e)
{
   ToolStripManager.Renderer = new Office2007Renderer();
}

There are a couple of other steps you might need to take at design time. If you are using a StatusStrip, then you need to update the render mode because, by default, it will not use the global one specified in the line of code above. So for each StatusStrip, you just need to click the smart tag and set the RenderMode to be ManagerRenderMode. Likewise for any ToolStripContainer that is created, just left click in the center of the container area, and then look in the Properties window for the RenderMode and again change it to ManagerRenderMode.

Points of Interest

I would have made the context menu have rounded corners just like Office 2007, but this is not possible because of the way the tool strips have been implemented. The background of the context menu is always drawn in a color that takes up the entire client area of the popup window. So it was not possible to simulate a rounded corner by not drawing the corner pixels. I could not find a way to set a region for the popup window either. Maybe someone else will have better luck.

History

This custom renderer was created as part of the development process of adding the Office 2007 appearance to the Krypton Toolkit. The Krypton Toolkit is a free set of controls for .NET 2.0 Windows Forms applications. It implements the full Office 2007 appearance for all of its controls including buttons, panels, headers, and so forth. You can download the free toolkit from here.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
Founder of Component Factory and currently working on developing professional user interface controls for VS2005 and .NET2.

You can check out our Krypton Toolkit free library at http://www.componentfactory.com/products.php

Comments and Discussions

 
QuestionRender tab Pin
thachvv1824-Jul-07 5:38
thachvv1824-Jul-07 5:38 
AnswerRe: Render tab Pin
jpmsoft14-Jul-08 15:10
jpmsoft14-Jul-08 15:10 
Questionslow draw Pin
thachvv1817-Jul-07 8:20
thachvv1817-Jul-07 8:20 
Questionhow to renderer progressbar on status strip Pin
Abolfazl Khusniddinov5-Jun-07 3:03
Abolfazl Khusniddinov5-Jun-07 3:03 
AnswerRe: how to renderer progressbar on status strip Pin
KoaQiu5-Jun-07 21:53
KoaQiu5-Jun-07 21:53 
GeneralUsing Office 2007 ToolStrip Rendere in CodePlex projects Pin
marco.minerva23-May-07 22:40
marco.minerva23-May-07 22:40 
GeneralRe: Using Office 2007 ToolStrip Rendere in CodePlex projects Pin
Lex Li17-Feb-08 17:52
professionalLex Li17-Feb-08 17:52 
GeneralBug in drop down checkmark rendering Pin
Scott Dorman17-Apr-07 6:19
professionalScott Dorman17-Apr-07 6:19 
When the renderer draws the "check" for checked tool strip menu items, it draws it too large if the tool strip's image scaling is set to something larger than the default 16x16.

This has been fixed in the latest release of the actual Krypton Toolkit, but for those who don't only need the renderer, here is one possible fix. (This is probably not how it was fixed in the toolkit, but it does work.)

In the protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) method of the Office2007Renderer class, add the following code (only what is italicized in bold, the rest is to provide context):

C#
// Staring size of the checkbox is the image rectangle
Rectangle checkBox = e.ImageRectangle;

<span style="font-size:10pt;font-weight:bold;font-style:italic"> 
// The default ImageScalingSize is 16x16, so we need to adjust the size
// if the toolstrip is set to something larger.
Size defaultScalingSize = new Size(16, 16);
 
if (Size.Subtract(e.ToolStrip.ImageScalingSize, defaultScalingSize) != Size.Empty)
{
   checkBox.Size = defaultScalingSize;
}
</span>
  
// Make the border of the check box 1 pixel bigger on all sides, as a minimum
checkBox.Inflate(1, 1);
 
// Can we extend upwards?


-----------------------------
In just two days, tomorrow will be yesterday.

GeneralKrypton Toolkit Pin
Amr Elsehemy ®11-Apr-07 6:03
Amr Elsehemy ®11-Apr-07 6:03 
GeneralThanks Pin
Nigel Shaw28-Feb-07 0:53
Nigel Shaw28-Feb-07 0:53 
GeneralOffice 2007 other themes Pin
Hadi Eskandari28-Jan-07 2:37
professionalHadi Eskandari28-Jan-07 2:37 
GeneralRe: Office 2007 other themes Pin
Angelo Cresta20-Jan-08 1:44
professionalAngelo Cresta20-Jan-08 1:44 
GeneralRe: Office 2007 other themes Pin
Thomas Stockwell22-May-08 4:37
professionalThomas Stockwell22-May-08 4:37 
GeneralButtons Pin
Angelo Cresta20-Dec-06 3:45
professionalAngelo Cresta20-Dec-06 3:45 
GeneralMenu Regions Pin
Z-Human14-Dec-06 10:47
Z-Human14-Dec-06 10:47 
GeneralInproper text size Pin
Jarosław Zwierz12-Dec-06 1:35
Jarosław Zwierz12-Dec-06 1:35 
GeneralRe: Inproper text size Pin
Jarosław Zwierz12-Dec-06 1:58
Jarosław Zwierz12-Dec-06 1:58 
GeneralRe: Inproper text size Pin
ComponentPhil12-Dec-06 12:16
ComponentPhil12-Dec-06 12:16 
QuestionDoes this contain call home software ? Pin
Reanalyse7-Dec-06 8:02
Reanalyse7-Dec-06 8:02 
AnswerRe: Does this contain call home software ? Pin
ComponentPhil7-Dec-06 11:23
ComponentPhil7-Dec-06 11:23 
GeneralRe: Does this contain call home software ? Pin
Reanalyse7-Dec-06 11:56
Reanalyse7-Dec-06 11:56 
GeneralLove your toolkit Pin
88Keys6-Dec-06 10:14
88Keys6-Dec-06 10:14 
GeneralKrypton Toolkit rocks Pin
Judah Gabriel Himango6-Dec-06 6:30
sponsorJudah Gabriel Himango6-Dec-06 6:30 
GeneralKrypton Toolkit is great Pin
Richard Guion6-Dec-06 5:56
Richard Guion6-Dec-06 5:56 
GeneralExcellent code Pin
tvbusy6-Dec-06 5:54
tvbusy6-Dec-06 5:54 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.