Click here to Skip to main content
11,431,307 members (67,559 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
(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 16-Jan-13 3:59am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Muhamad Faizan Khan at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
Muhamad Faizan Khan at 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)



Advertise | Privacy | Mobile
Web01 | 2.8.150428.2 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100