Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Showing only one instance of a form
Message
De
16/05/2006 02:31:37
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Showing only one instance of a form
Divers
Thread ID:
01122128
Message ID:
01122128
Vues:
57
I have a number of mmMaintenanceForms, which should only have one instance at a time.
Using the Windows Forms Jump Start code as an example, calling this code on the menu bar event:
mmAppDesktop.FormMgr.Show(new CustomerOrdersForm(), this);
will load multiple forms. This is fine for that form, but let's use that example to make it have only one instance at a time.

In MainForm.cs:
...
namespace Acme.OrderSystem.Main.Windows.Forms
{
    public partial class MainForm : mmMainAppForm
    {
        // list of form variables
        private CustomerOrdersForm customerOrdersForm;
        
        ...

        private void ActivitiesCustomerOrdersBar_Click(object sender, EventArgs e)
        {
            // show form once
            ShowCustomerOrdersForm();
        }

        private void ShowCustomerOrdersForm()
        {
            if (customerOrdersForm == null || customerOrdersForm.IsDisposed)
            {
                customerOrdersForm= new CustomerOrdersForm();
                mmAppDesktop.FormMgr.Show(customerOrdersForm, this);
            }
            else
            {
                customerOrdersForm.WindowState = FormWindowState.Normal;
                customerOrdersForm.BringToFront();
            }
        }
    }
}
Works fine, but for many forms, the duped code is going to get tedious. Is there a way to make a ShowOnce(form) method, and by reflection get the new instance of the passed form class?

Thanks!
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform