Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm right at the start of designing a small E:Mail control program for a friend, but would just like to ask some advice on best practice before I dive in at the deep end.

I have a Form with 2 ComboBoxes and the data selected decides what to send, what attachments to include and a SQL-Server database look-up will ascertain who to send the E:Mails to. This is currently designed in VS2010 Form Designer, not in the code.

I now want to add a ToolStrip with the following buttons: Send Mail (this is the current & main form), Preferences, Housekeeping (Database maintenance) ...

So ... When the user chooses Preferences or Housekeeping, should I hide my Main Form & display a new Form, then if he chooses Send Mail again, I hide this new Form & re-open the hidden Main Form ... ad infinitum so that there are 1 - 3 Forms but only one is visible at any time ...

Or ... Should I have just a single Form and I rebuild it in the code every time a Button is clicked ?
Posted
Updated 15-Jan-14 4:01am
v2

1 solution

If the application built as a single document interface (SDI); that is, you only ever need one instance of each of these windows, create each of the three screens as separate User Controls in Form Designer. Create one instance of each for the duration of the application, and add or remove each of these three user controls to your main form as necessary. This is a little cleaner than hiding/showing them (If they were very complex forms I might hide/show to conserve resources).

You will note that I recommend using a User Control instead of a Form. You could actually use either, but this is what user controls are meant for. There are a few reasons.

  • User controls are lighter-weight.
  • User controls can be added to a form in the Form Designer and you can still interact with them. Sub-forms cannot be used in the Designer.
  • Forms require special preparation before being used (Form.TopLevel = false).

Example

 
Share this answer
 
v2
Comments
Gary Heath 15-Jan-14 10:23am    
That's interesting, I'll take a look, thank you ... I don't suppose you have a link to a small example of an application working like this, do you ? I always find it easier to understand something when I can see it in action ... I'm a mainframe programmer (COBOL) by trade and VB.net programming is so alien to what I am used to :-) !!!
Yvan Rodrigues 15-Jan-14 11:06am    
What the heck -- just for you: http://www.codeproject.com/Tips/711071/UserControls-as-SDI-Windows
Gary Heath 15-Jan-14 12:52pm    
Thank you ...
Yvan Rodrigues 15-Jan-14 13:02pm    
No problem. Please accept the solution, or let me know if you have any questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900