Click here to Skip to main content
Email Password   helpLost your password?
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

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralIs there a renderer with Windows 7 theme?
stax76
1:48 14 Aug '09  
Does anybody know if there is a renderer with Windows 7 theme and if NET 4.0 will include renderers with Vista and Windows 7 theme?
Generalnot properly recover default renderer
Unruled Boy
16:36 17 Jan '09  
when switch back to the default renderer(ToolStripProfessionalRenderer) by:

FooToolStrip.Renderer = new ToolStripProfessionalRenderer();

the height does not set back to default(28px), it's still very high(much larger than 28px), and font color does not set back to system default(black), it's still white.

Regards,
unruledboy_at_gmail_dot_com
http://www.xnlab.com

Generalmenu not properly rendered in windows 2003
Unruled Boy
15:43 17 Jan '09  
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.net
JoeFisher71
6:35 6 Nov '08  
I converted your renderer to vb.net and changed your menu(incorporating the same button colors and made a transparent rounded button when mouse is over item), added a vista form background, and created a vista button as well. Would you mind if I posted my code if I gave you credit for all of your code?
AnswerRe: renderer in vb.net
Jose M. Menendez Poó
7:36 6 Nov '08  
There's absolutely no problem as long as you mention my work.

Thanks for asking.

Remember to send me the link to the article! Looking forward to see it.

Jm
www.menendezpoo.com

General[Message Removed]
Katekortez
10:08 25 Oct '08  
Spam message removed
GeneralAbout new button generation
marclenoir2005
7:27 1 Sep '08  
hi Jose

i'd like to if this button is also available for vb 2005 or 2008.

2nd-) Let's say that i'm using vb 2005, how can i create this kind of button using code 2005?

Regards.
GeneralRe: About new button generation
Jose M. Menendez Poó
7:55 1 Sep '08  
Actually, the code provided with the article was made in vs 2005.

If you want the source code in VB, I strongly suggest using the Lutz Roeder's .Net Reflector to uncompile in VB Mode.

Thanks

Jm

QuestionLegal for commerical Application?
Omnicoder
9:58 31 May '08  
Is this legal in a commercial application?
QuestionThe control looks very good. Is there any way to implement the same look and feel in web pages of asp.net
Member 3144945
18:34 24 Feb '08  
The control looks very good. Is there any way to implement the same look and feel in web pages of asp.net Wink
AnswerRe: The control looks very good. Is there any way to implement the same look and feel in web pages of asp.net
The Dogcow Farmer
12:36 26 Jun '08  
Use images. No fading, but it works.

"Cookies are delicious delicacies." - Mozilla Foundation

QuestionLicence
Julian-w
0:26 31 Dec '07  
Hello,
first: your project is great!!!

My question:
I program an openSource control library, them all controls of Windows Vista contains and a library for playing media files. I would use your sourcecode with a little modification (only namespace and class-name) in these projects.
Can I do this?

My Site: julian-w.de

(Sorry for my bad English, I'm from Germany)

GeneralFighting the tools
Mount
23:57 30 Dec '07  
Very good work, at least showing that winforms was underused when it came to graphics. The big problem is that
1) it takes a lot of code to do compared with WPF
2) it gets even harder when you try skin all the other controls like the datagridview, panels etc which are essential if you want a complete application. Look at http://www.componentfactory.com/[^] and see the amount of work it takes to create complete applicatios in winforms. This is a project by 1 guy
GeneralHow do I do this with just the command buttons?
JonathanVQP
7:55 19 Dec '07  
Can I do this with just a form that has command button instead of the toolstrip?
GeneralRe: How do I do this with just the command buttons?
The Dogcow Farmer
6:10 27 Jun '08  
Set the ToolStrip with a button's Dock property to none and move it there.

"Cookies are delicious delicacies." - Mozilla Foundation

GeneralTranslation to vb.net [modified]
virtual.aussie
11:13 26 Nov '07  
I made a translation in vb.net. Can I upload it or send it on email to you do it?

-- modified at 5:56 Tuesday 27th November, 2007
Generaljust move to WPF
dimzon
7:48 21 Nov '07  
actually if you need sexy and fine UI just move to WPF instead of WinForms
AnswerRe: just move to WPF
mofle
12:43 21 Nov '07  
Yes, but then i have to learn XAML.
GeneralRe: just move to WPF
dimzon
6:28 22 Nov '07  

mofle wrote:
Yes, but then i have to learn XAML.

no, you can do it in code Wink but yes, XAML make this much more easy Wink
actualy WPF and XAML is our future so we MUST learn it...
GeneralRe: just move to WPF
mofle
6:52 22 Nov '07  
Yes, but most people still use Windows XP and only have .NET 2.0, so if we want to get to the biggest crowd, we still have to use .NET 2.0 and WinForms.
GeneralRe: just move to WPF
The_Mega_ZZTer
6:12 23 Nov '07  
.NET 3.5 installs just fine on XP.

But you're right, not many people are going to have it yet; at least until Microsoft pushes it out over Automatic Updates, then we can start developing applications that use it.

Actually, did they do it already? I can't tell since I just downloaded and installed it the day it came out.
GeneralRe: just move to WPF
mofle
6:18 23 Nov '07  
Yes, you're right.

Anyway, i haven't used XP in over a year, so i can't answer you on that one.
GeneralRe: just move to WPF
Simon Capewell
6:44 23 Nov '07  
And what if you've been asked to spruce up and existing application? Porting the entire application would be a huge and risky job.


GeneralRe: just move to WPF
User of Users Group
9:55 23 Nov '07  
Not only that, it has been widely ack-ed by even MSFT themselves that WPF in fact makes your apps by default look very ugly. To make an awesome WPF app you really need designers involved.

And of course unless you are satisfied with an additional 5-fold (that is 500% for those that love diminishing returns) hit on CPU, and naturally an additional 30 MB of runtime bloat at the very least.

WPF has its purposes sure, and it has some great features (mainly enhanced experience from JS/DOM, markup history and plenty of 'nickage' from SVG too), but it is long shot away from being widespread, stable, efficient or a tech you want to bet your company on.

Go on then, adopt it so our customers can be happier Smile


QuestionTextbox problem
mofle
9:56 20 Nov '07  
When i add a TextBox to the ToolStrip the text isn't visible.

I can't find a solution to turn the text to black.

Can somebody help me?


Last Updated 23 Nov 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010