0

I am using VisualStyleRenderer for my Windows Application, it works perfectly for Windows XP theme but it doesn't work for Windows Classic theme. Can anybody suggest me how will I able to make application theme supportable.

Update:

Let me describe it with a clear picture. I have a list View and on the List Items I am drawing a button by using VisualStyleRenderer class and also Painting that Button region using some Gradient Color. It works in Windows XP theme but while I am changing the Theme to Windows Classic that button wffect is not coming which I have drawn by using VisualStyleRenderer class.

Any help will be appreciated

Thanks in advance.

SharpUrBrain
  • 3,180
  • 5
  • 38
  • 56
  • 1
    I think it will be easier to give you good answers if you describe how it is not working. – Fredrik Mörk Feb 28 '11 at 11:19
  • ok then let me give you a clear picture I have a list View and on the List Items I am drawing a button by using VisualStyleRenderer class and also Painting that Button region using some Gradient Color. It works in Windows XP theme but while I am changing the Theme to Windows Classic that button wffect is not coming which I have drawn by using VisualStyleRenderer class. – SharpUrBrain Feb 28 '11 at 11:34
  • 1
    It's difficult to imagine what you *expect* to happen. Look at the other buttons displayed on your screen: what visual style are they rendered in? The "Classic" 3D style, right? So why should your application render them any differently? It would stick out like a sore thumb if it did. That's the whole point of visual styles, to theme all windows/controls on your screen consistently. – Cody Gray - on strike Feb 28 '11 at 11:36
  • @Cody: Can you please mind to give me any link or sample example which will give me some hints to develop my application in a better way – SharpUrBrain Feb 28 '11 at 11:40
  • I see nothing *wrong* with your application. When the Classic theme is selected, you don't have visual styles turned on on your computer in the first place. My answer below provides more details, but the point is you can't render things in visual styles using `VisualStyleRenderer` when there are no visual styles. I'd use an `if` statement, in the style of [this example](http://msdn.microsoft.com/en-us/library/ms171735.aspx). – Cody Gray - on strike Feb 28 '11 at 12:01

1 Answers1

3

It's not going to happen. There are no "visual styles" for the Windows Classic theme. That's what they mean by "Classic": it's the theme that was used for years before visual styles were invented.

Windows XP's Luna theme is the first one to support visual styles. The Aero theme included with Windows Vista and 7 also supports visual styles, though they look slightly different.

If you use the VisualStyleRenderer class as you're doing, things will paint according to the theme that the user has selected. As you've said, everything looks fine when you select the Windows XP theme. When you have the Classic theme selected, things paint using the Classic theme. That's the expected behavior; everything else in the system looks different, too.

You will need to check and see if visual styles are supported, and if not, fall back to a different drawing method. There's a sample available here on MSDN. The simplest thing to do is add an if statement that evaluates the value returned by the Application.RenderWithVisualStyles property. If true, you can draw using the VisualStyleRenderer class. If false, you need to kick it old school. Using the ControlPaint class might be a good way to do that.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574