> This will take you into productivity heaven. 20 lines of code instead of
one.
I agree! But depends on the availability of attributes. :-)
Ok. Just one line. ;-)
using System.Reflection; // define this name space above
object aObj = textBox1;
string aProp = "eNaBled";
object aValue = false;
// One line here.
TypeDescriptor.GetProperties(aObj).Find(aProp, true).SetValue(aObj, aValue);
//*********************************************
object aObj = textBox1;
string aProp = "text";
object aValue = "Foxite Rocks!";
// One line here.
TypeDescriptor.GetProperties(aObj).Find(aProp, true).SetValue(aObj, aValue);
But then, as what Cetin says: it's not the only way.
There are many ways to make the code shorter. Let's say:
Much shorter.
textBox1.Enabled = true;
:-P
but if you have one-to-many object within a collection stored, i'll use the code provided above.
e.g.
string aProp = "enabled";
object aValue = false;
ArrayList aList = new ArrayList();
// selected object to be disabled
aList.Add(textBox1);
aList.Add(listBox1);
aList.Add(panel1);
foreach(object aObj in aList)
{
TypeDescriptor.GetProperties(aObj).Find(aProp, true).SetValue(aObj, aValue);
}
Note: all object added in the collection must exist.
Just a sharing. :-)
Best Regards,
CriZ (,")
"Happiness is real when shared."