|
-
Nov 29th, 2009, 10:31 AM
#1
Thread Starter
PowerPoster
Create UI dynamically
Hi all,
I want to create a UI dynamically. Simply say in a form I've a text box and a button. I can specify a number in that text box and click on the button. Once click on it the size of the form change and display same amount of text boxes in the UI. How can I do this in C#? Can anyone of you help me on this. Hope my question is clear enough.
Thanks.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
-
Nov 29th, 2009, 08:48 PM
#2
Re: Create UI dynamically
Just like any other objects, TextBoxes get created by invoking the class constructor and then configured by setting properties. You then display it on the form by adding it to the form's Controls collection.
The best way to figure out how to write code to create controls is to create a test app and add your controls in the designer and then simply open the designer code file, which you can access in the Solution Explorer, and read the code. You can then write code to do the same thing.
One thing you may find a bit of a pain is the spacing for multiple controls created at run time. The easiest way to accomplish that is to add a TableLayoutPanel to your form at design time and then add your run time controls to that. It will position the controls automatically.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|