How to Invoke a property in C#

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

I know how to call Invoke on a method, but I can't figure out HOW to call
Invoke on a property to set it's value.

Does anyone know how to do this?

Thanks,
Tony
 
Tony said:
I know how to call Invoke on a method, but I can't figure out HOW to call
Invoke on a property to set it's value.

Obtain the 'PropertyInfo' object for the property using the 'Type' object
and call its 'SetValue' method to assign a value to the property.
 
I don't see a 'PropertyInfo' object off the Type.

I'm trying to set the PictureBox.Image property.

Tony
 
Hello,

using System.ComponentModel;

PropertyDescriptor MyPropertyDescriptor =
TypeDescriptor.GetProperties(MyObject)["PropertyName"];

PropertyDescriptor contains lost of info about a property as well as helps
you to reset, set and get the value of a property. Dig MSDN for further info
about this class....

Regards,

Özden

Tony said:
I don't see a 'PropertyInfo' object off the Type.

I'm trying to set the PictureBox.Image property.

Tony
 
Tony said:
I don't see a 'PropertyInfo' object off the Type.

I'm trying to set the PictureBox.Image property.

Sample:

\\\
Me.GetType().GetProperty("BackColor").SetValue(Me, Color.Red, Nothing)
///
 
Back
Top