Reputation: 2356
I have a section of a form where the controls (text boxs, labels etc) need to be built at run time depending on options a user has selected. There will probably be about 7 - 10 different layouts in all.
What's the best way to go about creating and maintaining them?
Cheers Luke
Upvotes: 1
Views: 135
Reputation: 19841
All WinForms controls has corresponding classes (Button, Link, EditBox etc.) You can create any controls you want and attach them to form.
Inside the form Init you can add new controls into Controls collection.
public void Init()
{
this.Controls.Add(new TextBox());
}
Some more details in MSDN:
http://msdn.microsoft.com/en-us/library/0h5y8567.aspx
Upvotes: 0
Reputation: 3314
I have actually had to do just this. I did it with a set of panels (as @David suggests) and also a TreeView. Using the tree view, I customized the visuals to make them mimic an options menu in Microsoft Office, and then I show the appropriate panel based on the user's selection of nodes. If you'd like to see code samples let me know.
Upvotes: 0
Reputation: 2272
It would be helpful to know more about the specifics of your situation (what kind of options are we talking about?)
But off the top of my head, I'd guess you probably want to create a set of Panel
s which would contain the appropriate controls then hide or show them depending on the options.
Upvotes: 5