Professional Programmer Notes

or just call this my soapbox

Fix Visual Style of Tab Control in .NET

with one comment

I was having an issue with my tab contols looking very ugly:

Ugly Tab

These controls did not look anything like other fancy tab controls that I have seen recently in XP and Vista.    My tab control sucked.  Looking at it took away my desire to use my application.

I made several attempts at remedying the issue.  I tried one combination of property changes after another to no avail.  I was on the verge of creating a new owner-drawn tab control ( I had created a new project in Visual C# Express and everything) when I stumbled upon a CodeProject article.

I didn’t follow the article all the way through because it seemed to be written for an older version of the Framework and IDE.  But, it reminded me that there is an Application.EnableVisualStyles() method*.

I swiftly made sure I called that method before any controls were drawn, saved my hard work, and clicked the VS “Play” button with the excitement and anticipation of a child in line at Chuck E. Cheese.  That all died quickly when I received a screen containing the same ugly tabs staring back at me.

I checked the return value of the Application.RenderWithVisualStyles property and discovered my application was not using visual styles.  Thanks to the MSDN documentation, I quickly found the problem.  I had XP’s Appearance set to Windows Classic style.  Doh!!!

After changing XP’s Appearance back to Windows XP style, I had beautiful tabs:

Beautiful Tabs

To recap the solution:

  1. Call Application.EnableVisualStyles() before any controls get rendered.  In Program.cs just before Application.Run is a good place.
  2. Make sure you are allowing your OS to use visual styles.
  3. Don’t judge me for being absent-minded most of the time.  I’m trying to get it out of the way so that I won’t be absent-minded when I’m older.

* I probably saved over that memory with a Mitch Hedberg joke or my wedding anniversary date.

Advertisements

Written by curtismitchell

May 17, 2008 at 9:38 am

Posted in .net, CSharp, vb.net

Tagged with , , , ,

One Response

Subscribe to comments with RSS.

  1. It sinks!!!

    Syresh

    July 20, 2010 at 5:27 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: