471,627 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

showing a form

Ant
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
Jan 27 '06 #1
2 1238
Ant wrote:
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
Jan 27 '06 #2
Ant
Thank you very much MuZZY,

regards

Ant

"MuZZy" wrote:
Ant wrote:
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

Jan 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.