Just the form closing or application closing?

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

    Just the form closing or application closing?

    I've been looking but can't find out how in a form Closing event to know if
    the closing is because the form's "X" had been clicked or the main form's
    "X" was clicked.

    That is, I need to know if just the form is closing or the application is
    closing.

    Do you know how to tell?


    Thanks



  • tomb

    #2
    Re: Just the form closing or application closing?

    **Developer** wrote:
    [color=blue]
    >I've been looking but can't find out how in a form Closing event to know if
    >the closing is because the form's "X" had been clicked or the main form's
    >"X" was clicked.
    >
    >That is, I need to know if just the form is closing or the application is
    >closing.
    >
    >Do you know how to tell?
    >
    >[/color]
    I had this same puzzle - I just set a global flag when the program is
    closing, so the form can check it.

    Tom
    [color=blue]
    >
    >Thanks
    >
    >
    >
    >
    >[/color]

    Comment

    • AMercer

      #3
      Re: Just the form closing or application closing?

      > I had this same puzzle - I just set a global flag when the program is[color=blue]
      > closing, so the form can check it.[/color]

      I do the same thing. In simple apps, it doesn't matter much. But with
      several forms and/or several threads and/or several open resources, you are
      kind of fixed. An-app wide shutting down flag seems like the simplest
      solution.

      Comment

      • AMercer

        #4
        Re: Just the form closing or application closing?

        > How do you set the flag.

        I set it in the main form's closing event handler.
        [color=blue]
        > I believe the other form's Closing event occurs before the main form's
        > closing event.[/color]

        In my apps, if I close the main window, its closing event fires first,
        shutdown is indicated, and then secondary windows close. If I close a
        secondary window, its closing event fires, but nothing else happens.

        Comment

        • **Developer**

          #5
          Re: Just the form closing or application closing?

          I'm working on a MDI app.

          It has forms that are non-MDI child and some that are.

          The non-MDI child work as you say but the child always closes first.

          You said "shutdown is indicated."

          How do you check that?

          Maybe I can use that somehow.

          Thanks


          "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
          news:E3B98387-665B-4894-901A-3EF46D7DD2F7@mi crosoft.com...[color=blue][color=green]
          >> How do you set the flag.[/color]
          >
          > I set it in the main form's closing event handler.
          >[color=green]
          >> I believe the other form's Closing event occurs before the main form's
          >> closing event.[/color]
          >
          > In my apps, if I close the main window, its closing event fires first,
          > shutdown is indicated, and then secondary windows close. If I close a
          > secondary window, its closing event fires, but nothing else happens.
          >[/color]


          Comment

          • AMercer

            #6
            Re: Just the form closing or application closing?

            > I'm working on a MDI app.

            No experience with mdi. Perhaps events fire differently?
            [color=blue]
            > You said "shutdown is indicated."
            > How do you check that?[/color]

            In a public module, declare the shutdown flag, something like:

            Public Module SomeNameYourCho ice
            Public AppIsShuttingDo wn As Boolean = False
            End Module

            In the main form's closing event:

            AppIsShuttingDo wn = True

            In other places that need to know if the app is shutting down or not:

            If AppIsShuttingDo wn Then
            ' whatever you want if shutting down
            Else
            ' whatever you want if not shutting down
            Endif

            Comment

            • **Developer**

              #7
              Re: Just the form closing or application closing?

              Thanks
              I knew how to do that.
              I was hoping one of the Closing event arguments had a clue or maybe the
              Application class did.
              I had looked but couldn't find anything.

              Thanks again


              "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
              news:C0DC6487-6D86-44B1-9379-C312B01EF746@mi crosoft.com...[color=blue][color=green]
              >> I'm working on a MDI app.[/color]
              >
              > No experience with mdi. Perhaps events fire differently?
              >[color=green]
              >> You said "shutdown is indicated."
              >> How do you check that?[/color]
              >
              > In a public module, declare the shutdown flag, something like:
              >
              > Public Module SomeNameYourCho ice
              > Public AppIsShuttingDo wn As Boolean = False
              > End Module
              >
              > In the main form's closing event:
              >
              > AppIsShuttingDo wn = True
              >
              > In other places that need to know if the app is shutting down or not:
              >
              > If AppIsShuttingDo wn Then
              > ' whatever you want if shutting down
              > Else
              > ' whatever you want if not shutting down
              > Endif
              >[/color]


              Comment

              Working...