Click here to Skip to main content
13,044,539 members (60,022 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 18 Dec 2006

A control for skinning groups of controls

, 18 Dec 2006
Rate this:
Please Sign up or sign in to vote.
A control used to mass change other controls' properties.

Sample screenshot


What is a skin control, you may ask? A skin control is a control that can change the properties of many other controls quickly. For instance, in an application, you want to have the ability to have a green color scheme, a blue color scheme, etc. By using this control, you can specify the property (either by name or built-in) and what you want to set the property as. Quick, easy, and saves a ton of code. Here's how...

How it Works

How does this code work. It is actually quite simple. Included are a couple of methods to change some common properties like Name, Backcolor, Forecolor, etc. Along with these, you can also say you only want certain types to change, like only change the Forecolor of controls of type Button. But what if you want to change the property of a custom control? Or one that isn't provided? Here is where Reflection comes in.

During run time, I don't explicitly know the type of the object given. So I have to use Reflection to get it, like so:

Dim objType As Type = ctrl.GetType()

This creates an object objType. The type of objType is that of the control ctrl. Then, we can get the property we want, given its name.

Dim propInfo As PropertyInfo = objType.GetProperty(PropertyName)

This gets the PropertyInfo of that object. By passing in the name of the property we want to change, we can get or set the property. All that's left is to change the property.

propInfo.SetValue(ctrl, val, Nothing)

ctrl is the control whose property we want to change. val is the new value. Nothing (null) is used for the index in the case of an array. I just threw this together, so I did not add the ability to change this. If there is enough demand, I can.

But Wait, There's a Catch...

In order to change the properties of the control, it must be passed ByRef(erence) to the skin control. This means that the skin control still hold a reference so the control cannot be GC'd. Calling the RemoveControl method will remove the reference to the control. That's about it. Hope this can teach a little bit about Reflection.


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


About the Author

United States United States
I am iwdu15, a college frosh who will be majoring in Computer Science. I use VB.Net, C#, C++, J#, Java, and some C.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
MohammadAmiry3-Apr-10 4:47
memberMohammadAmiry3-Apr-10 4:47 
GeneralShortcomings Pin
mmansf19-Dec-06 4:21
membermmansf19-Dec-06 4:21 
GeneralRe: Shortcomings Pin
iwdu15019-Dec-06 10:37
memberiwdu15019-Dec-06 10:37 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 18 Dec 2006
Article Copyright 2006 by iwdu150
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid