Home All Groups Group Topic Archive Search About

Get property at runtime

Author
3 Dec 2006 3:32 AM
iwdu15
Hi, im making a tool used to Skin controls. Im trying to make it so a user
can change any property they want by passing the property in....for example

Public Sub ChangeProperty(Byval Prop as Propert, byval Value as Object)

now obviously that doesnt work because Property isnt a type...how can i do
this? thanks

--
-iwdu15

Author
3 Dec 2006 4:48 AM
iwdu15
nevermind, i figured it out....heres some code for any who need it

    Public Sub ChangeProperty(ByVal PropertyName As String, ByVal val As
Object, ByVal ctrl As Control)

                ''get the objects type and property info, passing in the
name of the property to get
                Dim objType As Type = ctrl.GetType()
                Dim propInfo As PropertyInfo =
objType.GetProperty(PropertyName)

                propInfo.SetValue(ctrl, val, Nothing)

            Catch ex As Exception



            End Try

    End Sub

--
-iwdu15
Author
3 Dec 2006 10:38 PM
Herfried K. Wagner [MVP]
"iwdu15" <jmmgoalsteratyahoodotcom> schrieb:
> Hi, im making a tool used to Skin controls. Im trying to make it so a user
> can change any property they want by passing the property in....for
> example
>
> Public Sub ChangeProperty(Byval Prop as Propert, byval Value as Object)
>
> now obviously that doesnt work because Property isnt a type...how can i do
> this?

In addition to the other reply, check out VB's handy 'CallByName' function.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>