using reflection with property of type system.drawing.color  
Author Message
Trophus





PostPosted: Visual C# Language, using reflection with property of type system.drawing.color Top

Hello All:

I have a problem trying to use reflection with a property of type System.Drawing.Color
When i use PropertyInfo.SetValue(object, MyPropInfo, null) to set a property it throws the error
"Cannot Convert System.Reflection.PropertyInfo to Type System.Drawing.Color".

Is it even possible to do this

TIA
Trophus

"You kill one bug...and fifty show up for the funeral"





Visual C#3  
 
 
Eric Oostergo





PostPosted: Visual C# Language, using reflection with property of type system.drawing.color Top

Hi,

As far as I can see, you are using your property information as a parameter instead of using it to set a property on an object.

I just tested the following code by creating a windows forms application and adding this code to the Form load event:

PropertyInfo propertyInformation = this.GetType().GetProperty("BackColor");

if (propertyInformation != null)
{
propertyInformation.SetValue(
this, System.Drawing.Color.Blue, null);
}

As you can see I use the GetType method of the Form class to get the type and then I call GetProperty on the type. If all goes well I have a valid PropertyInfo object that allows me to set the BackColor property of any object of the same type.

I then use this PropertyInfo object to set the value of the form (this) with a new value of System.Drawing.Color.Blue.

I hope this helps....

Eric.


 
 
Trophus





PostPosted: Visual C# Language, using reflection with property of type system.drawing.color Top

Eric

Thats the ticket!

Thanks Much

Trophus