Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Making the form open once (http://www.programmingforums.org/showthread.php?t=13616)

Robocop Jul 24th, 2007 5:37 PM

Making the form open once
 
What I want to do is to make it so that if the form is already opened, it shouln't open again until it is closed... also I don't want to use ShowDialog().

I tried this:
:

    frmSecondary frm = new frmSecondary();
    if (frm.Shown == false)
    {
          frm.Show();
    }


But I'm getting this error:
:

Error        1        The event 'System.Windows.Forms.Form.Shown' can only appear on the left hand side of += or -=

jaeusm Jul 24th, 2007 5:58 PM

'Shown' is an event, not a boolean value. You might want to consider the 'Visible' property.

crawforddavid2006 Jul 24th, 2007 6:03 PM

try something like this
:

  1.     frmSecondary frm = new frmSecondary();
  2.     bool frmShow = false;
  3.     if (frmShow == false)
  4.     {
  5.           frm.Show();
  6.     }


also, i didnt compile the code, i just typed it out so let me know if it doesnt work right

john Wesley Jul 24th, 2007 6:39 PM

Of course it wont work 'right' - the condition will never result to true.

What I suggest you do is track the forms Load and Closing events, setting variables appropriately so that conditional statements have a non-futile use.

crawforddavid2006 Jul 24th, 2007 7:01 PM

Quote:

Originally Posted by john Wesley (Post 131089)
Of course it wont work 'right' - the condition will never result to true.

well i knew you needed an else statement, i just didnt know what he wanted in there. i make 1 mistake and everyone is all over it:rolleyes:

john Wesley Jul 25th, 2007 9:04 AM

That one mistake could easily cause you headaches in the future - does you best to keep a sharp eye.


All times are GMT -5. The time now is 2:32 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC