nlwelch
asked on
Trouble Creating forms dynamically
I am trying to build a form dynamically. I have a class that I've created to do the dirty work. The class accepts a form and attempts to recreate it dynamically. The class walks through the controls and attempts to recreate them using the System.Reflection namespace. Everything works great accept for the properties with complex types. For example, the Alignment property is System.Windows.Forms.TabAl ignment enumeration type. How do I convert the value "Top" to the System.Windows.Forms.TabAl ignment.To p enumerated value?
(System.Windows.Forms.TabA lignment) enum.Parse(typeof(System.W indows.For ms.TabAlig nment), "Top")
But if you use reflection, you might need to get the type first right? Then it might be
Type t = Type.GetType("System.Windo ws.Forms.T abAlignmen t");
object o = enum.Parse(t, "Top")
then you can use reflection setvalue to set value to System.Windows.Forms.TabAl ignment.To p
Type t = Type.GetType("System.Windo
object o = enum.Parse(t, "Top")
then you can use reflection setvalue to set value to System.Windows.Forms.TabAl
ASKER
ok - now how do I execute the same statement but with following comments:
(System.Windows.Forms.TabA lignment) - this value is retrieved from a configuration file and stored in a string. How do I create the same typecast using a string?
typeof(System.Windows.Form s.TabAlign ment) - again, this value is stored in a string. How do I use typeof with a string variable?
Thanks for your help so far!!!
(System.Windows.Forms.TabA
typeof(System.Windows.Form
Thanks for your help so far!!!
ASKER
i can't get it to compile - it fails on the enum.Parse. What am I missing?
oops... sorry
it should be Enum not enum.
it should be Enum not enum.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.