Reputation: 5299
I calling my form by buttonclick:
var form = new GPZUWizardForm(
Модуль.ИнформацияОСессии,
Модуль.IngeoApplication,
кодВИнгео,
pzzMapObjectId,
кодЗУ,
номерСтраницы,
гпзу);
if (!form.Visible)
Application.Run(form);
When i click button second time form showing again.
How to show only one form in once?
Upvotes: 0
Views: 62
Reputation: 442
IF it is not MDI, iterate through each opened Form to see if it's opened and close it if that's what you need. Here's a quick example of how to do that:
for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
{
if (Application.OpenForms[i].Name != "MyFormThatIDon'tWantToClose" && Application.OpenForms[i].Name != "TheOTherFormThatIDontWantToClose" )
Application.OpenForms[i].Close();
}
Upvotes: 0
Reputation: 919
If you are using MDI parent then before opening any form you need to check whether that form is already open or not. If it is open first close that instance and open new instance.
Upvotes: 0
Reputation: 116
Thats because you are creating a new instance of the form everytime.
You can use the singleton pattern.
http://www.dotnetperls.com/singleton
Upvotes: 2