Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(behind a button)

Read_QuranoTafsir readQuran = new Read_QuranoTafsir();
readQuran.Show();
readQuran.MdiParent = this;


This is my new form code it is working fine but the problem is
as i click my button a form appear.
i click again another form appear this thing continues as i click again and again.
i want to restrict my form to not open more then 1 if the form is alread active.
please HELP
Posted

Two simple solutions.

Set a flag when you open your form, clear it when you close.

Before you open your form, you check to see if the flag is set - hence the form is open, and you do nothing. If the flag is not set - you open the form.

Alternatively - disable button when the form opens, and reenable it when you close.
 
Share this answer
 
Comments
Muhamad Faizan Khan 16-Jan-13 9:20am    
Alternatively - disable button when the form opens, and reenable it when you close.
this soulution i understand but
the firs i didnt get . what is flag;-(
grimbeast 16-Jan-13 9:54am    
A flag is typically just a bool value. Then set it to true on formopen, and back to false on close - and then before open - check the value to figure out what to do.
Another option would be to make it a field which starts out null. When the user clicks the button, check the field, if null then instantiate and set the field. The problem being that you need to clear the field when the user closes the form.

There are other solutions involving mutexes (mutices?) as well.
 
Share this answer
 
Comments
Muhamad Faizan Khan 16-Jan-13 23:19pm    
i am new to c# ;-(

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