Prevent form from closing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sravan_reddy001

    Prevent form from closing

    i want to prevent a form from closing..

    to do this i want to handle the formClosing or FormClosed events.
    from here i want to prevent the form from closing.

    New instance of same form should not be used.

    is there any way to do this?

    is it posiible to do the same thing with anycode?

    [i posted the same thing in VB. sorry if u find that too... reply in
    one post is enough]

  • Peter Duniho

    #2
    Re: Prevent form from closing

    On Wed, 13 Jun 2007 18:57:15 -0700, sravan_reddy001
    <sravanganta200 2@gmail.comwrot e:
    i want to prevent a form from closing..

    [...]
    [i posted the same thing in VB. sorry if u find that too... reply in
    one post is enough]
    Please learn to cross-post properly, by including all newsgroups in
    Newsgroups: field of the same post, instead of multi-posting.

    Pete

    Comment

    • KWienhold

      #3
      Re: Prevent form from closing

      On 14 Jun., 03:57, sravan_reddy001 <sravanganta2.. .@gmail.comwrot e:
      i want to prevent a form from closing..
      >
      to do this i want to handle the formClosing or FormClosed events.
      from here i want to prevent the form from closing.
      >
      New instance of same form should not be used.
      >
      is there any way to do this?
      >
      is it posiible to do the same thing with anycode?
      >
      [i posted the same thing in VB. sorry if u find that too... reply in
      one post is enough]
      Setting e.Cancel to true in the FormClosing-event should do the trick.

      hth,
      Kevin Wienhold

      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: Prevent form from closing

        Hi,

        "KWienhold" <hedovvwr@trash mail.netwrote in message
        news:1181804727 .756141.87030@i 13g2000prf.goog legroups.com...
        On 14 Jun., 03:57, sravan_reddy001 <sravanganta2.. .@gmail.comwrot e:
        >i want to prevent a form from closing..
        >>
        >to do this i want to handle the formClosing or FormClosed events.
        >from here i want to prevent the form from closing.
        >>
        >
        Setting e.Cancel to true in the FormClosing-event should do the trick.
        You need something else, you need a flag to know when the form is closing
        from the code or is the user trying to close it.

        bool canClose = false;

        void form_Closing(.. .. )
        {
        e.Cancel = !canClose;
        }

        so if you want to close the form you do:

        canClose =true;
        Close();


        Comment

        Working...