Avatar of imrancs
imrancs
Flag for Pakistan asked on

How to prevent opening of new windows(or forms) at runtime when OpenNewForm(newItemForm etc) button is clicked.

Can any one tell me how to prevent to open many windows(or forms) when i click on OpenNewForm(newItemForm etc) button repeatedly, i want, only one window(or form ) should open  although i click it several times.
C#

Avatar of undefined
Last Comment
lizard450

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
lizard450

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Gautham Janardhan

k...if Form1 is the parent form from where all ur windows are called what u could do is

declare all the Form in the form1 class like


public class Form1:S.W.Form
{
Form2 MyForm2;
Form3 MyForm3;
Form4 MyFrom4l

private void button1_click(object sender,System.Eventargs e)
{
if(Myfor2 == null || MyForm2.IsDisposed)
{
MyForm2 = new Form2();
}
MyForm2.Show()
}
//Similarly for all other forms
}
Gautham Janardhan

if ur forms access is spread throyughout the app then the best way would be to

maintain a list of all the open forms ..(add ur forms to an Hastable or something every time) and before opening a form check whether the form exists in the HashTable if so get the object from the table and show()
lizard450

Actually gauthampj I disagree if access is spread throughout the app the best way is to implement the pattern I pointed to above.  This way you don't have to "maintain" anything it all just works.  

However, if Form1 is the parent object then I would agree with you.  

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck