Click here to Skip to main content
15,868,164 members
Articles / Programming Languages / C#
Article

Visual Style Element Browser

Rate me:
Please Sign up or sign in to vote.
4.84/5 (19 votes)
12 Feb 2008CPOL1 min read 63.9K   4.7K   81   6
A simple tree which exposes the different VisualStyleElements available in NET 2.0
VisualElementBrowser

Introduction

I wrote this small utility app while working on the custom 'tree with columns' control, which you can see used in this same app. There is really not much to it, but I figured it might be useful for others working on custom controls.

A VisualStyleElement is a UI element exposed by the system and can be used by any custom control to draw a system control or element. In the case of the tree control, the visual element is used to draw the column and row headers.

More information regarding the visual styles can be found in System.Windows.Forms.VisualStyles namespace and here.

The only part that was a little tricky was to populate the tree. All elements are defined as nested static classes within VisualStyleElement (check it out with Reflector). After a little bit of trial and error I found it to be quite simple though, get the nested types and for each type get the static properties, and do this recursive. The code for this is in VisulalStyleTreeV1.AddType(type).

To paint the style in the tree, I created a derived class of CellPainter and overwrote PaintCell for the Style column (fieldname called image for this column !?)

And that is all.

Revision History

  • 2/12/2008: V1 uploaded
    A workaround fix for the hanging issue when running release. I don't understand why it would go into an infinite loop when run in release (but not when run in release from debugger), but the issue was resolved by moving 2 variables out of the CompareColorByBrightness method.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAbout the right hand side of your form Pin
CalWho17-Oct-22 10:37
CalWho17-Oct-22 10:37 
QuestionTextBox focus and Windows 7 Pin
pl.27-Oct-10 2:36
professionalpl.27-Oct-10 2:36 
GeneralNice Pin
NormDroid12-Feb-08 10:06
professionalNormDroid12-Feb-08 10:06 
GeneralBug report Pin
Dreamwolf12-Feb-08 0:33
Dreamwolf12-Feb-08 0:33 
GeneralRe: Bug report Pin
jkristia12-Feb-08 3:19
jkristia12-Feb-08 3:19 
I am running Vista myself, but I will try and find an XP and have this problem corrected.
GeneralRe: Bug report Pin
jkristia12-Feb-08 7:03
jkristia12-Feb-08 7:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.