Get property at runtime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iwdu15

    #1

    Get property at runtime

    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
  • iwdu15

    #2
    RE: Get property at runtime

    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.GetProp erty(PropertyNa me)

    propInfo.SetVal ue(ctrl, val, Nothing)

    Catch ex As Exception



    End Try

    End Sub

    --
    -iwdu15

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Get property at runtime

      "iwdu15" <jmmgoalsteraty ahoodotcomschri eb:
      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/>

      Comment

      Working...