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 Design, 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 ?

I have another suggestion which could be easier for you.

Leave your main form open, but open each of the other forms using the showdialog method.

This will open each form as a modal dialog box in front of your main form and will prevent the user interacting with any other part of the application until the form is closed e.g.

sub Config_Click(byval sender as object, byval e as system.events)
dim frmConfig as new ConfigForm 
frmConfig.showDialog
end sub

Remember to add a way of closing your dialog form in the dialog forms code, you can also return a dialog result from the dialog form to the main form for processing as well e.g.

Public Sub ShowMyDialogBox()
    Dim testDialog As New Form2()

    ' Show testDialog as a modal dialog and determine if DialogResult = OK. 
    If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then 
        ' Read the contents of testDialog's TextBox.
        txtResult.Text = testDialog.TextBox1.Text
    Else
        txtResult.Text = "Cancelled" 
    End If
    testDialog.Dispose()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.