Solved

Trouble Creating forms dynamically

Posted on 2003-12-09
6
243 Views
Last Modified: 2010-04-16
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.TabAlignment enumeration type.  How do I convert the value "Top" to the System.Windows.Forms.TabAlignment.Top enumerated value?
0
Comment
Question by:nlwelch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 18

Expert Comment

by:testn
ID: 9908582
(System.Windows.Forms.TabAlignment) enum.Parse(typeof(System.Windows.Forms.TabAlignment), "Top")
0
 
LVL 18

Expert Comment

by:testn
ID: 9908595
But if you use reflection, you might need to get the type first right? Then it might be

Type t = Type.GetType("System.Windows.Forms.TabAlignment");
object o =  enum.Parse(t, "Top")  

then you can use reflection setvalue to set value to System.Windows.Forms.TabAlignment.Top
 
0
 

Author Comment

by:nlwelch
ID: 9908596
ok - now how do I execute the same statement but with following comments:

(System.Windows.Forms.TabAlignment) - 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.Forms.TabAlignment) - again, this value is stored in a string.  How do I use typeof with a string variable?

Thanks for your help so far!!!

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:nlwelch
ID: 9908635
i can't get it to compile - it fails on the enum.Parse.  What am I missing?
0
 
LVL 18

Expert Comment

by:testn
ID: 9909696
oops... sorry

it should be Enum not enum.
0
 
LVL 18

Accepted Solution

by:
testn earned 500 total points
ID: 9909772
And it should be

Type t = typeof(System.Windows.Forms.Control).Assembly.GetType("System.Windows.Forms.TabAlignment");
object x = Enum.Parse(t,"Top");

object x will contain System.Windows.Forms.TabAlignment.Top
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question