Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Showing only one instance of a form
Message
From
16/05/2006 02:31:37
 
 
To
All
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Title:
Showing only one instance of a form
Miscellaneous
Thread ID:
01122128
Message ID:
01122128
Views:
56
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!
Next
Reply
Map
View

Click here to load this message in the networking platform