I have one main form, and i want to dynamically change it’s content, via pressing some buttons.
Let’s say i have a button “New user” and “Login”, and if I press new user, i don’t want to make new form + show, i want all labels and buttons of new user to be displayed right in the main form. And if i press login, the main form content to change to some labels and textboxes?
This is just for example.
All I can now, is just make new forms and show them to the user via .Show() command.
I have one main form, and i want to dynamically change it’s content, via
Share
Let’s say you have Customer, Product and Vendor “windows”. You don’t want to make separate windows from them, so you group all of their controls inside groupboxes and make them visible/invisible depending on user actions. This will work, but it leads to problems of code readability and maintainability: you’re writing a lot of code for a lot of controls inside your window which is, after all, just one class.
So you can do this: create a user control named usrCustomer or myCustomer or whatever, and paste into it all the controls related to Customer: the groupbox, the labels, the combos, everything. Then you can decide if you want to add this mega-control to your main form on design time or if you wanna create a new instance of it in run-time everytime you need it. If in the future you have to modify something, you’ll go to a separate class (ctlCostumer) instead of having to dig inside a monster main form class.
CAVEAT: you’ll have to be careful if those controls share information between them, (if the Product mega-control needs to know something from the Customer mega-control) and expose that info with public properties, etc.