Minimizing the whole application when the close button is click

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mylixes
    New Member
    • May 2010
    • 29

    Minimizing the whole application when the close button is click

    I have a Windows Application. I just don't understand why is it that when i click the Close button, instead of closing the form, it minimizes the whole application.
    I don't experience this on my previous runs. It's weird that I am now experiencing it. It's awkward also that I should restore the whole application to begin another transaction.

    Below is my code on Close button event.

    private void btnClose_Click( object sender, EventArgs e)
    {
    this.Close();
    }
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Is it a dialog form..
    Is doesn't seem to be possible though..

    can you post your code a bit more..

    Comment

    • Samishii23
      New Member
      • Sep 2009
      • 246

      #3
      Ok that is what it is doing.
      What do you want it to do?

      Comment

      • mylixes
        New Member
        • May 2010
        • 29

        #4
        Originally posted by Samishii23
        Ok that is what it is doing.
        What do you want it to do?
        I just want to close the form when i click the close button. It's just annoying that recently I experiencing that problem. When I click the close button, the form is closing and the other form minimizes. I want the other form to stay open.

        Comment

        • Samishii23
          New Member
          • Sep 2009
          • 246

          #5
          Do you have multiple forms in your application or are you looking for a full application close and not running any more? If thats the case...

          Code:
          Application.Exit(0);
          Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

          Comment

          • mylixes
            New Member
            • May 2010
            • 29

            #6
            Originally posted by Samishii23
            Do you have multiple forms in your application or are you looking for a full application close and not running any more? If thats the case...

            Code:
            Application.Exit(0);
            http://msdn.microsoft.com/en-us/library/ms157894.aspx
            Yes, I have multiple forms in my application. For example, Form1, Form2 and Form3 are all open at the same time. When I click the close button of Form3, I want to close Form3 only and I want Form1 and Form2 to stay open not minimized.
            What I am experiencing now is that, when I click the close button of Form3, Form1 and Form2 minimizes. I don't know what triggers that. It's weird because I haven't experienced that on my previous runs.

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              ThatThatGuy: Is doesn't seem to be possible though..
              Oh please... It is easy and commonly done.

              Do you have a method attached to the Form_Closing event handler?

              Its very easy to catch this event, set the closeargs to cancel, then minimize the form. It sounds like that's what is happening. Though it is odd that it is happening without you knowing you wrote that event handler. Are you collaborating with another coder? Does the problem form inherit from another form that might have this method?

              Code:
              void FormClosing(object sender, eventargs e)
              {
                 e.cancel = true; // cancel the closing
                 this.WindowState = WindowState.Minimize;// Or something to that effect.
              }

              Comment

              • ThatThatGuy
                Recognized Expert Contributor
                • Jul 2009
                • 453

                #8
                Originally posted by mylixes
                I have a Windows Application. I just don't understand why is it that when i click the Close button, instead of closing the form, it minimizes the whole application.
                I don't experience this on my previous runs. It's weird that I am now experiencing it. It's awkward also that I should restore the whole application to begin another transaction.

                Below is my code on Close button event.

                private void btnClose_Click( object sender, EventArgs e)
                {
                this.Close();
                }
                Can you post your code so that we could examine a bit

                Comment

                • mylixes
                  New Member
                  • May 2010
                  • 29

                  #9
                  Originally posted by ThatThatGuy
                  Can you post your code so that we could examine a bit
                  private void btnClose_Click( object sender, EventArgs e)
                  {
                  this.Close();
                  }
                  That's the only code i wrote for button close event.
                  The events I usually used are as follows:

                  1.OnLoad
                  2.Keypress and KeyDown to handle inputs
                  3.Close Event which is the code i posted above

                  Comment

                  • tlhintoq
                    Recognized Expert Specialist
                    • Mar 2008
                    • 3532

                    #10
                    Are you really asking "why does my application close, then I tell it to
                    This.Close();

                    Surely you aren't. And if you really don't understand why it is doing it... Give up coding now and go to cooking school instead.

                    You've already been given the code to override the form closing event and minimize instead. What more do you want?

                    Comment

                    • ThatThatGuy
                      Recognized Expert Contributor
                      • Jul 2009
                      • 453

                      #11
                      Originally posted by mylixes
                      private void btnClose_Click( object sender, EventArgs e)
                      {
                      this.Close();
                      }
                      That's the only code i wrote for button close event.
                      The events I usually used are as follows:

                      1.OnLoad
                      2.Keypress and KeyDown to handle inputs
                      3.Close Event which is the code i posted above
                      OK, If You want to close a Dialog Form.. then Preferably use this.Close()

                      Which closes just the Dialog Form..
                      Use Application.Exi t() or this.Dispose() to terminate the entire Application....

                      Comment

                      • tlhintoq
                        Recognized Expert Specialist
                        • Mar 2008
                        • 3532

                        #12
                        [highlight]O.P.: [/hightlight]when I click the close button of Form3, Form1 and Form2 minimizes. I don't know what triggers that.
                        Put a breakpoint on the line that opens Form3. And then debug it (F5)
                        Walk through your code with the F10 key.
                        When Form3 closes you should be taken to the code that is executed next. Walk through it until you hit the line minimizing your application.

                        Or, do a find (ctrl-F) for ".minimize" to see if you are minimizing your form. As well as ".Hide()"

                        Those would be the two most common ways to hide form1, which in turn hides all the child forms.

                        Comment

                        • mylixes
                          New Member
                          • May 2010
                          • 29

                          #13
                          Originally posted by tlhintoq
                          Put a breakpoint on the line that opens Form3. And then debug it (F5)
                          Walk through your code with the F10 key.
                          When Form3 closes you should be taken to the code that is executed next. Walk through it until you hit the line minimizing your application.

                          Or, do a find (ctrl-F) for ".minimize" to see if you are minimizing your form. As well as ".Hide()"

                          Those would be the two most common ways to hide form1, which in turn hides all the child forms.
                          Thanks for the help but I did that already.

                          Comment

                          Working...