Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have write a program which has an About button, pressing the about button on the main form will open another form which gives some information about the program, however, clicking the about button will make another instances of such form, how can I avoid it?

my code is:
C#
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
{
    FormAbout formAbout = new FormAbout();
    formAbout.Show();
}


Thanks in advance
AM
Posted
Updated 11-Mar-15 4:46am
v2

Simplest way is to use ShowDialog instead:
C#
private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
{
    FormAbout formAbout = new FormAbout();
    formAbout.ShowDialog();
}
 
Share this answer
 
I think OriginalGriff has given you a correct, solid, answer here;.

A factor in how you manage a "secondary" Form like this is the extent to which you need to do possibly "expensive" (time, memory) work to fill that secondary Form with its relevant content before you show it.

Why not create the Form once, populate its fields that do not change once, and then re-use the Form ... rather than creating a new instance of the secondary Form each time you want to show it ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900