Avatar of rwheeler23
rwheeler23
Flag 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?
C#

Avatar of undefined
Last Comment
AndyAinscow

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
gr8gonzo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
AndyAinscow

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61