Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

Opening forms using C#. Is one way better than another?

What is the difference between opening a form this way:


if (ViewGLDistributionsForm == null)
{
    ViewGLDistributionsForm = new frmViewGLDistributions();
}
else
{
    if (ViewGLDistributionsForm.Created == false)
    {
        ViewGLDistributionsForm = new frmViewGLDistributions();
    }

}

ViewGLDistributionsForm.Show();
ViewGLDistributionsForm.Activate();

Open in new window



...and opening it this way?

using (frmLookupBatchIDs LookupBatchIDsForm = new frmLookupBatchIDs(batchNumber))
{
    if (LookupBatchIDsForm.ShowDialog(this) == DialogResult.OK)
    {
        LookupBatchIDsForm.Show();
        LookupBatchIDsForm.Activate();
        LookupBatchIDsForm.Focus();
        batchNumber = LookupBatchIDsForm.CellValue;
    }
}

Open in new window



I am still learning C# and I see multiple ways to open forms. Is there a proper way or is one way better under one set of circumstances and another way better under another set of circumstances?
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial