cast string to control.Property
-
I have (button1 in my form) string nameProp = "button1.Text"; how can i set this property for button1.
-
I have (button1 in my form) string nameProp = "button1.Text"; how can i set this property for button1.
Start by reading a book.
I know the language. I've read a book. - _Madmatt
-
Start by reading a book.
I know the language. I've read a book. - _Madmatt
What do you mean ? Can u help?
-
I have (button1 in my form) string nameProp = "button1.Text"; how can i set this property for button1.
You can do like this
// find control
Control[] controls = this.Controls.Find("button1", true);if (controls.Length > 0)
{Control control = controls\[0\]; // get properties PropertyInfo\[\] properties = control.GetType().GetProperties(); foreach (PropertyInfo controlProperty in properties) { // check property name if (controlProperty.Name == "Text") { // set value of control controlProperty.SetValue(control, "My new Value", null); } }
}
----------------------------- Shakeel Iqbal ------------------------------ My New Article Task Manager
-
You can do like this
// find control
Control[] controls = this.Controls.Find("button1", true);if (controls.Length > 0)
{Control control = controls\[0\]; // get properties PropertyInfo\[\] properties = control.GetType().GetProperties(); foreach (PropertyInfo controlProperty in properties) { // check property name if (controlProperty.Name == "Text") { // set value of control controlProperty.SetValue(control, "My new Value", null); } }
}
----------------------------- Shakeel Iqbal ------------------------------ My New Article Task Manager
I know this one! I want something like this : string butt = "button1.Text"; (Button)butt="New Value";
-
I know this one! I want something like this : string butt = "button1.Text"; (Button)butt="New Value";
It can't be done the way you want. You have no choice but to use reflection as was demonstrated.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...