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

WindowsVistaRenderer: A New Button Generation

By , 23 Nov 2007
 
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jose Menendez Póo
Team Leader
Mexico Mexico
Member
Jose Manuel Menéndez Poó
 
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is user interface usability.
 
Questions and stuff by twitter: @menendezpoo
 
Jose Runs Goplek in Mexico
www.goplek.com
 
Blog
menendezpoo.com

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

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to Change background colorsmembervijayksingh2 Apr '13 - 2:15 
GeneralMy vote of 2memberprogrammerdon17 Oct '12 - 8:15 
QuestionBinariesmemberVercas21 Jun '11 - 2:55 
AnswerRe: BinariesmemberJose Menendez Póo21 Jun '11 - 3:05 
GeneralRe: BinariesmemberVercas21 Jun '11 - 3:21 
QuestionIs there a renderer with Windows 7 theme?memberstax7614 Aug '09 - 0:48 
Generalnot properly recover default renderermemberUnruled Boy17 Jan '09 - 15:36 
Generalmenu not properly rendered in windows 2003memberUnruled Boy17 Jan '09 - 14:43 
check out the snap shot
 
http://www.cnblogs.com/images/cnblogs_com/unruledboy/19874/o_VistaRendererMenu.jpg[^]
 
Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com

Questionrenderer in vb.netmemberJoeFisher716 Nov '08 - 5:35 
AnswerRe: renderer in vb.netmemberJose M. Menendez Poó6 Nov '08 - 6:36 
General[Message Removed]memberKatekortez25 Oct '08 - 9:08 
GeneralAbout new button generationmembermarclenoir20051 Sep '08 - 6:27 
GeneralRe: About new button generationmemberJose M. Menendez Poó1 Sep '08 - 6:55 
QuestionLegal for commerical Application?memberOmnicoder31 May '08 - 8:58 
QuestionThe control looks very good. Is there any way to implement the same look and feel in web pages of asp.netmemberMember 314494524 Feb '08 - 17:34 
AnswerRe: The control looks very good. Is there any way to implement the same look and feel in web pages of asp.netmemberThe Dogcow Farmer26 Jun '08 - 11:36 
QuestionLicencememberJulian-w30 Dec '07 - 23:26 
GeneralFighting the toolsmemberMount30 Dec '07 - 22:57 
QuestionHow do I do this with just the command buttons?memberJonathanVQP19 Dec '07 - 6:55 
AnswerRe: How do I do this with just the command buttons?memberThe Dogcow Farmer27 Jun '08 - 5:10 
GeneralTranslation to vb.net [modified]membervirtual.aussie26 Nov '07 - 10:13 
Generaljust move to WPFmemberdimzon21 Nov '07 - 6:48 
AnswerRe: just move to WPFmembermofle21 Nov '07 - 11:43 
GeneralRe: just move to WPFmemberdimzon22 Nov '07 - 5:28 
GeneralRe: just move to WPFmembermofle22 Nov '07 - 5:52 
GeneralRe: just move to WPFmemberThe_Mega_ZZTer23 Nov '07 - 5:12 
GeneralRe: just move to WPFmembermofle23 Nov '07 - 5:18 
GeneralRe: just move to WPFmemberSimon Capewell23 Nov '07 - 5:44 
GeneralRe: just move to WPFmemberUser of Users Group23 Nov '07 - 8:55 
QuestionTextbox problemmembermofle20 Nov '07 - 8:56 
AnswerRe: Textbox problemmemberJose M. Menendez Poo21 Nov '07 - 3:50 
GeneralRe: Textbox problemmembermofle21 Nov '07 - 4:10 
QuestionRe: Textbox problemmembermofle22 Nov '07 - 8:30 
QuestionRe: Textbox problemmembermofle28 Nov '07 - 23:51 
GeneralToolStripComboBox IssuememberMichal Brylka13 Nov '07 - 5:12 
AnswerRe: ToolStripComboBox IssuememberJose M. Menendez Poo21 Nov '07 - 3:49 
GeneralMenuStrip ProblemmemberSk8tz27 Oct '07 - 0:55 
AnswerRe: MenuStrip ProblemmemberStaffanW21 Nov '07 - 3:40 
GeneralRe: MenuStrip ProblemmemberSk8tz21 Nov '07 - 3:57 
GeneralRe: MenuStrip ProblemmemberSk8tz22 Nov '07 - 20:33 
AnswerRe: MenuStrip ProblemmemberJose M. Menendez Poo23 Nov '07 - 4:14 
GeneralRe: MenuStrip ProblemmemberSk8tz23 Nov '07 - 4:32 
GeneralRe: MenuStrip ProblemmemberSk8tz26 Nov '07 - 19:34 
GeneralToolstripSplitButton Problemmembergrouperb126 Oct '07 - 4:20 
GeneralRe: ToolstripSplitButton ProblemmemberJose M. Menendez Poo26 Oct '07 - 4:28 
GeneralRe: ToolstripSplitButton Problem Possible Solutionmembergrouperb126 Oct '07 - 21:33 
GeneralMuy buen trabajo Jose!memberPakT25 Oct '07 - 22:14 
GeneralRe: Muy buen trabajo Jose!membersk8er_boy28711 Dec '08 - 1:28 
GeneralPretty coolmemberBen Daniel25 Oct '07 - 18:10 
GeneralSuggestionmemberMCAST7625 Oct '07 - 7:55 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 23 Nov 2007
Article Copyright 2007 by Jose Menendez Póo
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid