5,401,186 members and growing! (18,845 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Vista API » Graphics     Intermediate

WindowsVistaRenderer: A New Button Generation

By Jose M. Menendez Poó

ToolStripRenderer that renders Vista like buttons
C# 2.0, C#Windows, .NET, .NET 2.0, VistaVS2005, Visual Studio, Dev, Design

Posted: 15 Oct 2007
Updated: 23 Nov 2007
Views: 51,756
Bookmarked: 191 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
106 votes for this Article.
Popularity: 9.60 Rating: 4.74 out of 5
2 votes, 1.9%
1
2 votes, 1.9%
2
1 vote, 1.0%
3
12 votes, 11.4%
4
88 votes, 83.8%
5
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:

//

// 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 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

About the Author

Jose M. Menendez Poó


Jose Manuel Menéndez Poó
Mexico

I've been programming Windows and Web apps since 1997.

My greatest concern nowadays is user interface usability.

My blog: www.menendezpoo.com
Occupation: Team Leader
Location: Mexico Mexico

Other popular Vista API articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 55 (Total in Forum: 55) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionLegal for commerical Application?memberOmnicoder9:58 31 May '08  
QuestionThe control looks very good. Is there any way to implement the same look and feel in web pages of asp.netmemberMember 314494518:34 24 Feb '08  
AnswerRe: The control looks very good. Is there any way to implement the same look and feel in web pages of asp.netmemberThe Dogcow Farmer12:36 26 Jun '08  
QuestionLicencememberJulian-w0:26 31 Dec '07  
GeneralFighting the toolsmemberMount23:57 30 Dec '07  
GeneralHow do I do this with just the command buttons?memberJonathanVQP7:55 19 Dec '07  
GeneralRe: How do I do this with just the command buttons?memberThe Dogcow Farmer6:10 27 Jun '08  
GeneralTranslation to vb.net [modified]membervirtual.aussie11:13 26 Nov '07  
Generaljust move to WPFmemberdimzon7:48 21 Nov '07  
AnswerRe: just move to WPFmembermofle12:43 21 Nov '07  
GeneralRe: just move to WPFmemberdimzon6:28 22 Nov '07  
GeneralRe: just move to WPFmembermofle6:52 22 Nov '07  
GeneralRe: just move to WPFmemberThe_Mega_ZZTer6:12 23 Nov '07  
GeneralRe: just move to WPFmembermofle6:18 23 Nov '07  
GeneralRe: just move to WPFmemberSimon Capewell6:44 23 Nov '07  
GeneralRe: just move to WPFmemberUser of Users Group9:55 23 Nov '07  
QuestionTextbox problemmembermofle9:56 20 Nov '07  
AnswerRe: Textbox problemmemberJose M. Menendez Poo4:50 21 Nov '07  
GeneralRe: Textbox problemmembermofle5:10 21 Nov '07  
QuestionRe: Textbox problemmembermofle9:30 22 Nov '07  
QuestionRe: Textbox problemmembermofle0:51 29 Nov '07  
GeneralToolStripComboBox IssuememberMichal Brylka6:12 13 Nov '07  
AnswerRe: ToolStripComboBox IssuememberJose M. Menendez Poo4:49 21 Nov '07  
GeneralMenuStrip ProblemmemberSk8tz1:55 27 Oct '07  
AnswerRe: MenuStrip ProblemmemberStaffanW4:40 21 Nov '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Nov 2007
Editor: Sean Ewington
Copyright 2007 by Jose M. Menendez Poó
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project