Creating Single-Instance Forms

At times you may want to create a single-instance form--a form that has only one instance. If a user selects a single-instance form multiple times, it simply brings the selected form to front (if it's hidden behind another form).

To create a single instance form, you can implement the Singleton design pattern. For example, the MM .NET sample application's Employee Form is single instance and implements the Singleton pattern by means of this static (Shared), read-only property.

In C#:

public static EmployeeForm FormInstance
{
	get
	{
		if (_formInstance == null || _formInstance.IsDisposed)
		{
			_formInstance = new EmployeeForm();
		}
		return _formInstance;
	}
}
private static EmployeeForm _formInstance;

And in VB .NET:

Public Shared ReadOnly Property FormInstance() As EmployeeForm
   Get
      If _formInstance Is Nothing OrElse _formInstance.IsDisposed Then
         _formInstance = New EmployeeForm()
      End If
      Return _formInstance
   End Get
End Property
Private Shared _formInstance As EmployeeForm

To instantiate the form, you can call the Form Manager's Show() method like this in C#:

mmAppDesktop.FormMgr.Show(EmployeeForm.FormInstance, this);

And in VB .NET:

mmAppDesktop.FormMgr.Show(EmployeeForm.FormInstance, Me)

© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/20/09
Comment or report problem with topic