Get property at runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 said:
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.
 
Back
Top