There are many approaches you could use. Singleton form is only one of them, but an elegant one:
http://hashfactor.wordpress.com/2009/03/31/c-winforms-create-a-single-instance-form/[
^]
[update]
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace SingletonForm
{
public class SingletonForm : Form
{
#region Singleton pattern specific
private static SingletonForm SingleInstance;
public static SingletonForm Instance
{
get
{
if(SingleInstance == null)
{
SingleInstance = new SingletonForm();
SingleInstance.FormClosing += new FormClosingEventHandler(Singleton_FormClosing);
}
return SingleInstance;
}
}
private static void Singleton_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
SingleInstance.Hide();
}
public new void Show()
{
if (base.Visible)
base.Select();
else
{
base.Show();
}
}
#endregion
#region Generated
private System.ComponentModel.IContainer components = null;
public SingletonForm()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
#endregion
private void InitializeComponent()
{
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Child";
this.Name = "Child";
}
}
public class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(59, 33);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(190, 47);
this.button1.TabIndex = 0;
this.button1.Text = "Start the other form";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.Button1Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(303, 116);
this.Controls.Add(this.button1);
this.Name = "MainForm";
this.Text = "Main Form";
this.ResumeLayout(false);
}
private System.Windows.Forms.Button button1;
void Button1Click(object sender, System.EventArgs e)
{
SingletonForm.Instance.Show();
}
}
public class Program
{
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}