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

WindowsVistaRenderer: A New Button Generation

Rate me:
Please Sign up or sign in to vote.
4.86/5 (141 votes)
23 Nov 2007CPOL3 min read 283.3K   8.2K   322   71
ToolStripRenderer that renders Vista like buttons
Screenshot - VistaRenderer.jpg

Introduction

This article demonstrates how to use the WindowsVistaRenderer and how it was created.

Background

Don't you miss the days when a button was drawn with a couple of lines to show a 3D effect? Drawing a button was as simple as drawing the light border and the shadow border. Those days are gone. Vista has arrived and our old apps may need to be renewed.

The first time you look at a button like the ones on Vista look and feel, you must feel dizzy. How to draw buttons like that? Well it turns out that it is not such a great deal. It took me a while to totally understand how these buttons are drawn, but I think the result is a good approach.

Using the Code

Thank God for the ToolStripRenderer technology.

To use this renderer on a ToolStrip you only need one line of code:

C#
//
// Apply Windows Vista look and feel
//

toolStrip1.Renderer = new Renderers.WindowsVistaRenderer();

The Renderer initializes the necessary properties for the ToolStrip, except for the LayoutStyle property which I recommend to be the default HorizontalStackWithOverflow, otherwise the toolbar may look ugly in some cases.

The source solution contains a project named Renderers. Reference that DLL to your project or copy the source files to your project.

How to Draw a Button Like That

As I said before, the old-school buttons were drawn in a very easy way:

Screenshot - VistaRenderer1.gif Screenshot - VistaRenderer2.gif

The whole idea is to make the user think that he or she is really pushing a button, when clicked shadows were inverted, text pushed one pixel on x and one pixel on y, and the click effect was done.

The Vista buttons are way more complex. I've found different layers on the button drawing.

Borders

Three rounded rectangles are drown as a border, I call them the outer border, the border and the inner border.

Screenshot - VistaRenderer3.gif

Glossy Effect

A glossy effect is drawn on the north of the button. The green color represents an almost transparent color.

Screenshot - VistaRenderer4.gif

Glow

A radial gradient simulates a color glow on the south of the button. The green color represents an almost tansparent color.

Screenshot - VistaRenderer5.gif

Button Fill

Similar to the glossy effect, the inner border area is emphasized with a linear button fill from north to south.

Putting It All Together

Now, the order in which we draw these layers is critical. That order is:

  1. Outer border
  2. Button background color (if button is checked)
  3. Glossy effect
  4. Border
  5. Button fill glossy emphasis
  6. Inner border
  7. Glow
  8. Text and image of the button
Screenshot - VistaRenderer6.jpg

Some Other Details

To create the click effect, the color of the inner border and the button fill are changed. When clicked, the text is not pushed one pixel like in the old days.

When checked, the background color of the button changes. That color was extracted from the tabs on the MediaPlayer.

To make the toolbar a full-Vista-experience component, menus are drawn using the Windows Vista look and feel.

Credits

Thanks to Lukasz Swiatkowski for the methods on creating rounded rectangles and the bottom radial path.

History

  • 15 Oct 2007: Article creation
  • 25 Oct 2007: Subitem initialization by recursion solved (suggested by rvpilot)
  • 21 Nov 2007: Combobox and Textbox support. Better overflow chevron.
  • 23 Nov 2007: MenuStrip support.

License

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


Written By
Product Manager
United States United States
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is product, user interface, and usability.
- TypeScript / React expert

@geeksplainer

Comments and Discussions

 
GeneralToolStripComboBox Issue Pin
Michal Brylka13-Nov-07 5:12
Michal Brylka13-Nov-07 5:12 
AnswerRe: ToolStripComboBox Issue Pin
JoseMenendez21-Nov-07 3:49
JoseMenendez21-Nov-07 3:49 
GeneralMenuStrip Problem Pin
Sk8tz27-Oct-07 0:55
professionalSk8tz27-Oct-07 0:55 
AnswerRe: MenuStrip Problem Pin
StaffanW21-Nov-07 3:40
StaffanW21-Nov-07 3:40 
GeneralRe: MenuStrip Problem Pin
Sk8tz21-Nov-07 3:57
professionalSk8tz21-Nov-07 3:57 
GeneralRe: MenuStrip Problem Pin
Sk8tz22-Nov-07 20:33
professionalSk8tz22-Nov-07 20:33 
AnswerRe: MenuStrip Problem Pin
JoseMenendez23-Nov-07 4:14
JoseMenendez23-Nov-07 4:14 
GeneralRe: MenuStrip Problem Pin
Sk8tz23-Nov-07 4:32
professionalSk8tz23-Nov-07 4:32 
Thanks will test

Sk8tZ

GeneralRe: MenuStrip Problem Pin
Sk8tz26-Nov-07 19:34
professionalSk8tz26-Nov-07 19:34 
GeneralToolstripSplitButton Problem Pin
leninvarsamis26-Oct-07 4:20
leninvarsamis26-Oct-07 4:20 
GeneralRe: ToolstripSplitButton Problem Pin
JoseMenendez26-Oct-07 4:28
JoseMenendez26-Oct-07 4:28 
GeneralRe: ToolstripSplitButton Problem Possible Solution Pin
leninvarsamis26-Oct-07 21:33
leninvarsamis26-Oct-07 21:33 
GeneralMuy buen trabajo Jose! Pin
PakT25-Oct-07 22:14
PakT25-Oct-07 22:14 
GeneralRe: Muy buen trabajo Jose! Pin
Emil - Gabriel11-Dec-08 1:28
Emil - Gabriel11-Dec-08 1:28 
GeneralPretty cool Pin
Ben Daniel25-Oct-07 18:10
Ben Daniel25-Oct-07 18:10 
GeneralSuggestion Pin
MCAST7625-Oct-07 7:55
MCAST7625-Oct-07 7:55 
GeneralInitializeItem(..) is not recursive ! Pin
rvpilot22-Oct-07 10:01
rvpilot22-Oct-07 10:01 
NewsRe: InitializeItem(..) is not recursive ! [modified] Pin
JoseMenendez25-Oct-07 3:36
JoseMenendez25-Oct-07 3:36 
GeneralWonderful, thanks! Pin
Tomas Deml19-Oct-07 4:50
Tomas Deml19-Oct-07 4:50 
GeneralBeautiful Control Pin
NiteBeast17-Oct-07 15:12
NiteBeast17-Oct-07 15:12 
Generalcolor palette Pin
TheCardinal16-Oct-07 21:55
TheCardinal16-Oct-07 21:55 
GeneralRe: color palette Pin
JoseMenendez17-Oct-07 3:33
JoseMenendez17-Oct-07 3:33 
GeneralNice job Pin
v# guy16-Oct-07 0:37
v# guy16-Oct-07 0:37 
GeneralRe: Nice job Pin
Vertyg016-Oct-07 11:01
Vertyg016-Oct-07 11:01 
GeneralRe: Nice job Pin
Irwan Hassan30-Oct-07 5:59
Irwan Hassan30-Oct-07 5:59 

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.