HOW TO TRAP FORM TO LOAD ONLY ONCE
-
HI I'M NEW TO C# I'M CREATING MENU AND DONE BUT THE PROBLEM IS WHEN I CLICK THE MENU ITEM 3 TIMES THE FORM WILL SHOW 3 TIMES AND I WANT TRAP THAT IF THE FORM ALREADY LOADED YOU CANT OPEN THE FORM TWICE UNLESS THE USER CLOSE THE FORM.. HOW TO TRAP FORM TO LOAD ONLY ONCE
-
HI I'M NEW TO C# I'M CREATING MENU AND DONE BUT THE PROBLEM IS WHEN I CLICK THE MENU ITEM 3 TIMES THE FORM WILL SHOW 3 TIMES AND I WANT TRAP THAT IF THE FORM ALREADY LOADED YOU CANT OPEN THE FORM TWICE UNLESS THE USER CLOSE THE FORM.. HOW TO TRAP FORM TO LOAD ONLY ONCE
If you use
ShowDialog()
insteadShow()
. If you use ShowModal(), you will prevent code execution till you close your form. OR declare Form with a global or class scope. And you can put boolean value inside form. And use OnLoad event and Close event to set it to true or false. And before showing you should check that boolean. PS: It is rude to shout -
If you use
ShowDialog()
insteadShow()
. If you use ShowModal(), you will prevent code execution till you close your form. OR declare Form with a global or class scope. And you can put boolean value inside form. And use OnLoad event and Close event to set it to true or false. And before showing you should check that boolean. PS: It is rude to shout -
First way:
Form form1 = new Form();
form1.ShowDiealog();second way:
// Not tested, writing from memory;
public class testForm : Form
{
...
public bool opend;private void testForm_OnLoad(Object sender, EventArgs e)
{
opend = true;
}private void testForm_OnClosing(Object sender, EventArgs e)
{
opend = false;
}
...
}// class scope wariable - Same as testForm.opend. At least i think it is called class scope.
testForm form1 = new testForm(1);
// Inside menu item method click.
if (!form1.opend)
form1.Show();
else
form1.Focus(); -
HI I'M NEW TO C# I'M CREATING MENU AND DONE BUT THE PROBLEM IS WHEN I CLICK THE MENU ITEM 3 TIMES THE FORM WILL SHOW 3 TIMES AND I WANT TRAP THAT IF THE FORM ALREADY LOADED YOU CANT OPEN THE FORM TWICE UNLESS THE USER CLOSE THE FORM.. HOW TO TRAP FORM TO LOAD ONLY ONCE
Writing a post in all capital letters is the on-line equivilent of yelling at the top of your lungs. Read the forum rules post at the top of every forum.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...