showing a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, this is a simple question.

i want to click a button to show a form. If I use this code:

button_click()
{
MyNewForm myNewForm = new MyNewForm;
myNewForm.Show();
}

every time I click the button I get multiple instances of the form.
Understandably.

If I move the instantiation of the MyNewForm object out of the method so
that its a class scope field:


MyNewForm mynewform = new MyNewForm;

button_click()
{
myNewForm.Show();
}

This solves the multiple click problem, as it just keeps "showing" the form
object, but if I close the form and hence destroy the instance of the form, I
can no longer show the file and an error is raised as the form no longer
exists. Understandably.

This must be a common procedure. How does everyone do this??

Many thanks for your answers to this.

Ant
 
Ant said:
Hi, this is a simple question.

i want to click a button to show a form. If I use this code:

button_click()
{
MyNewForm myNewForm = new MyNewForm;
myNewForm.Show();
}

every time I click the button I get multiple instances of the form.
Understandably.

If I move the instantiation of the MyNewForm object out of the method so
that its a class scope field:


MyNewForm mynewform = new MyNewForm;

button_click()
{
myNewForm.Show();
}

This solves the multiple click problem, as it just keeps "showing" the form
object, but if I close the form and hence destroy the instance of the form, I
can no longer show the file and an error is raised as the form no longer
exists. Understandably.

This must be a common procedure. How does everyone do this??

The common procedure will be:

MyNewForm mynewform = new MyNewForm;

button_click()
{
if (myNewForm == null || myNewForm.Disposing || myNewForm.IsDisposed())
myNewForm = new MyNewForm();
myNewForm.Show();
}


Good luck,
MuZZy
 
Thank you very much MuZZY,

regards

Ant

MuZZy said:
The common procedure will be:

MyNewForm mynewform = new MyNewForm;

button_click()
{
if (myNewForm == null || myNewForm.Disposing || myNewForm.IsDisposed())
myNewForm = new MyNewForm();
myNewForm.Show();
}


Good luck,
MuZZy
 
Back
Top