Solved

Trouble Creating forms dynamically

Posted on 2003-12-09
6
237 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
  • 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now