Monday, August 21, 2006

Application.RenderWithVisualStyles - Maybe

Just a quick note about the System.Windows.Forms.Application.RenderWithVisualStyles property in the .NET 2.0.

I had to write some manual resizing/layout code the other day and I discovered that I needed to alter the size and location of some controls differently depending on whether XP themes were enabled or not. I'm still not quite sure why this was the case, but one set of values certainly wasn't right asthetically in both cases.

It seems the RenderWithVisualStyles property is supposed to tell you whether or not controls and forms inside your application should render 'themed'. This is based on a number of things, such as whether visual styles have been enabled for your application, whether they're supported and enabled in the OS etc.

Well, the property works fine until you change settings with your application open. If you do this, the value of the property doesn't appear to change until your application is restart - even though the standard Windows Forms controls (such as the Button control) will alter their display without the application being restarted. This means you can end up with a situation where RenderWithVisualStyles returns the wrong value compared with what's being drawn on screen.

Of course, most people probably won't change this setting often with your application open and it will correct itself as soon as the application is restarted, but it's still something to be aware of.

No comments:

Post a comment