Another Kind of Eval

  • Thread starter Thread starter Nicolas
  • Start date Start date
N

Nicolas

Is there a way to have a handle on a control having only the control name
So I dont have to loop through all the controls nested on the form.
checking for the control name = my string
this could be long and heavy on memory

Assuming the control name is "btn_Save"

How to get to ctr being the required control so that I can apply changes
ctr.GetType().GetProperty(oProperty).SetValue( ctr,newVal, null);
 
Nicolas,

You are on the right track. Instead of using GetProperty on the Type
instance, use the GetField method on the type containing the control. This
will return the individual fields. Once you have that, you can get an
object that represents the value in the field and get the property on THAT
object, and then set it.

Hope this helps.
 
Thanks but still a bit confuse there
this been my form
button2 been the control that I know the name of
gave me error.

this.GetType().GetField("button2").GetType().GetProperty("BackColor").SetValue(this.GetType().GetField("button2"),Color.Red,null);

Can you help on that syntax?

Thank you.



Nicholas Paldino said:
Nicolas,

You are on the right track. Instead of using GetProperty on the Type
instance, use the GetField method on the type containing the control. This
will return the individual fields. Once you have that, you can get an
object that represents the value in the field and get the property on THAT
object, and then set it.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

Nicolas said:
Is there a way to have a handle on a control having only the control name
So I dont have to loop through all the controls nested on the form.
checking for the control name = my string
this could be long and heavy on memory

Assuming the control name is "btn_Save"

How to get to ctr being the required control so that I can apply changes
ctr.GetType().GetProperty(oProperty).SetValue( ctr,newVal, null);
 
Back
Top