New Listview-style headers... an easy route?

MrPaul

Contributor
Joined
Jun 28, 2006
Messages
428
Location
Hampshire, UK
SOLVED: New Listview-style headers... an easy route?

Greetings. Long time reader, first time poster...

I am building a custom control, the fabled 'TreeList' (columns like a listview but with collapsible sections like a treeview) with bells on, both because it is the ideal method of displaying what I wish to display, and because it's an ideal way to practice some control development.

Now on to the question. Using the ControlPaint class its dead easy to draw the column headers ala Windows 2000. However, these blocky buttons can look a bit out of place when surrounded by other controls which have adopted the system theme on XP. So, I'm asking if there is any simple way (or even not so simple, Im a big boy!) of getting the look of the 'stylish' listview-style column header buttons when the system theme is so, and the old-skool blocky column headers otherwise.

(See image below).

Thanks peeps.
 

Attachments

Last edited:
System.Windows.Forms.VisualStyles is the answer!

I plead guilty to posting with a little too much haste. The answer was out there, I just couldn't see it.

It would seem the sneaky devils at Microsoft have added a new namespace in 2.0, which I have only recently aquired. System.Windows.Forms.VisualStyles contains everything the budding control designer needs. Now we know.

C#:
vsr = new VisualStyleRenderer(VisualStyleElement.Header.Item.Normal);
vsr.DrawBackground(e.Graphics, rect);
e.Graphics.DrawString(col.Name, this.Font, rectf);

Tada! :rolleyes:
 
Back
Top