Shutting down GUI apps

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

    Shutting down GUI apps


    I have a windows GUI application (vb.net 2.0) and I need to manage how
    it is closed. I want to have a single function that is called whenever
    the user tries the close the app regardless of how:


    * User selects File|Exit from the main menu
    or clicks a [Close] button.


    * the system is being shut down via the [X]
    button, or the system menu from the task
    bar (etc.)


    My objective is to have this function perform the following tests:


    [1] if there isn't a current document loaded
    return True

    [2] if the current document isn't "dirty",
    return True

    [3] prompt the user to save the document. If
    that succeeds, return True. If the save
    fails or the user cancels the action,
    Return False


    If the function returns True, the shut down will be allowed to
    continue. If it returns false, the shut down will be aborted.


    Any suggestions on the best approaches to take for this?


    Ralf
    --
    --
    ----------------------------------------------------------
    * ^~^ ^~^ *
    * _ {~ ~} {~ ~} _ *
    * /_``>*< >*<''_\ *
    * (\--_)++) (++(_--/) *
    ----------------------------------------------------------
    There are no advanced students in Aikido - there are only
    competent beginners. There are no advanced techniques -
    only the correct application of basic principles.



  • Stephany Young

    #2
    Re: Shutting down GUI apps

    You already have it.

    It is called the FormClosing event of the Form class.


    "_AnonCowar d" <abc@xyz.comwro te in message
    news:45afb2f1$0 $9628$4c368faf@ roadrunner.com. ..
    >
    I have a windows GUI application (vb.net 2.0) and I need to manage how
    it is closed. I want to have a single function that is called whenever
    the user tries the close the app regardless of how:
    >
    >
    * User selects File|Exit from the main menu
    or clicks a [Close] button.
    >
    >
    * the system is being shut down via the [X]
    button, or the system menu from the task
    bar (etc.)
    >
    >
    My objective is to have this function perform the following tests:
    >
    >
    [1] if there isn't a current document loaded
    return True
    >
    [2] if the current document isn't "dirty",
    return True
    >
    [3] prompt the user to save the document. If
    that succeeds, return True. If the save
    fails or the user cancels the action,
    Return False
    >
    >
    If the function returns True, the shut down will be allowed to
    continue. If it returns false, the shut down will be aborted.
    >
    >
    Any suggestions on the best approaches to take for this?
    >
    >
    Ralf
    --
    --
    ----------------------------------------------------------
    * ^~^ ^~^ *
    * _ {~ ~} {~ ~} _ *
    * /_``>*< >*<''_\ *
    * (\--_)++) (++(_--/) *
    ----------------------------------------------------------
    There are no advanced students in Aikido - there are only
    competent beginners. There are no advanced techniques -
    only the correct application of basic principles.
    >
    >
    >

    Comment

    • _AnonCoward

      #3
      Re: Shutting down GUI apps


      "Stephany Young" <noone@localhos twrote in message
      news:uoryrsyOHH A.400@TK2MSFTNG P04.phx.gbl...
      :
      : You already have it.
      :
      : It is called the FormClosing event of the Form class.

      That's just seems too simple! But it works. I looked a little closer
      at the FormClosingEven tArgs parameter to the function and sure enough,
      setting the cancel property to True aborted the shut down. How about
      that...

      That's what I needed. Thanx,

      Ralf


      : "_AnonCowar d" <abc@xyz.comwro te in message
      : news:45afb2f1$0 $9628$4c368faf@ roadrunner.com. ..
      : >
      : I have a windows GUI application (vb.net 2.0) and I need to manage
      : how it is closed. I want to have a single function that is called
      : whenever the user tries the close the app regardless of how:
      : >
      : >
      : * User selects File|Exit from the main menu
      : or clicks a [Close] button.
      : >
      : >
      : * the system is being shut down via the [X]
      : button, or the system menu from the task
      : bar (etc.)
      : >
      : >
      : My objective is to have this function perform the following tests:
      : >
      : >
      : [1] if there isn't a current document loaded
      : return True
      : >
      : [2] if the current document isn't "dirty",
      : return True
      : >
      : [3] prompt the user to save the document. If
      : that succeeds, return True. If the save
      : fails or the user cancels the action,
      : Return False
      : >
      : >
      : If the function returns True, the shut down will be allowed to
      : continue. If it returns false, the shut down will be aborted.
      : >
      : >
      : Any suggestions on the best approaches to take for this?
      : >
      : >
      : Ralf
      : --
      : --
      : ----------------------------------------------------------
      : * ^~^ ^~^ *
      : * _ {~ ~} {~ ~} _ *
      : * /_``>*< >*<''_\ *
      : * (\--_)++) (++(_--/) *
      : ----------------------------------------------------------
      : There are no advanced students in Aikido - there are only
      : competent beginners. There are no advanced techniques -
      : only the correct application of basic principles.


      Comment

      • Stephany Young

        #4
        Re: Shutting down GUI apps

        I'm glad you've got it sussed.

        It's not 'too simple'. That's exactly what that event is designed for.

        Note that the FormClosingEven tArgs parameter also has a property that gives
        the reason for the form closing. One of the reasons is that Windows is
        hutting down. When that is the reason you may need to consider bypassing
        your logic.


        "_AnonCowar d" <abc@xyz.comwro te in message
        news:45affd46$0 $5759$4c368faf@ roadrunner.com. ..
        >
        "Stephany Young" <noone@localhos twrote in message
        news:uoryrsyOHH A.400@TK2MSFTNG P04.phx.gbl...
        :
        : You already have it.
        :
        : It is called the FormClosing event of the Form class.
        >
        That's just seems too simple! But it works. I looked a little closer
        at the FormClosingEven tArgs parameter to the function and sure enough,
        setting the cancel property to True aborted the shut down. How about
        that...
        >
        That's what I needed. Thanx,
        >
        Ralf
        >
        >
        : "_AnonCowar d" <abc@xyz.comwro te in message
        : news:45afb2f1$0 $9628$4c368faf@ roadrunner.com. ..
        : >
        : I have a windows GUI application (vb.net 2.0) and I need to manage
        : how it is closed. I want to have a single function that is called
        : whenever the user tries the close the app regardless of how:
        : >
        : >
        : * User selects File|Exit from the main menu
        : or clicks a [Close] button.
        : >
        : >
        : * the system is being shut down via the [X]
        : button, or the system menu from the task
        : bar (etc.)
        : >
        : >
        : My objective is to have this function perform the following tests:
        : >
        : >
        : [1] if there isn't a current document loaded
        : return True
        : >
        : [2] if the current document isn't "dirty",
        : return True
        : >
        : [3] prompt the user to save the document. If
        : that succeeds, return True. If the save
        : fails or the user cancels the action,
        : Return False
        : >
        : >
        : If the function returns True, the shut down will be allowed to
        : continue. If it returns false, the shut down will be aborted.
        : >
        : >
        : Any suggestions on the best approaches to take for this?
        : >
        : >
        : Ralf
        : --
        : --
        : ----------------------------------------------------------
        : * ^~^ ^~^ *
        : * _ {~ ~} {~ ~} _ *
        : * /_``>*< >*<''_\ *
        : * (\--_)++) (++(_--/) *
        : ----------------------------------------------------------
        : There are no advanced students in Aikido - there are only
        : competent beginners. There are no advanced techniques -
        : only the correct application of basic principles.
        >
        >

        Comment

        • Phill W.

          #5
          Re: Shutting down GUI apps

          Stephany Young wrote:
          I'm glad you've got it sussed.
          >
          It's not 'too simple'. That's exactly what that event is designed for.
          Agreed.

          Am I the only one that thinks it "sad" that people regard a
          well-designed and well-functioning VB feature such as this as being "too
          simple" in this Brave New World of .Net?

          Regards,
          Phill W.

          Comment

          • Stephany Young

            #6
            Re: Shutting down GUI apps

            Not at all Phill. I'm sure there are, at least, a few of us.

            While, I don't have a problem with people striving for an acedemically or
            technically 'pure' way of doing something, per se, I do tend to give people
            an earful when I do hear them trotting out the 'there must be a better way
            because that way is too simple' line.


            "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
            news:eoqi6o$1vi $1@south.jnrs.j a.net...
            Stephany Young wrote:
            >I'm glad you've got it sussed.
            >>
            >It's not 'too simple'. That's exactly what that event is designed for.
            >
            Agreed.
            >
            Am I the only one that thinks it "sad" that people regard a well-designed
            and well-functioning VB feature such as this as being "too simple" in this
            Brave New World of .Net?
            >
            Regards,
            Phill W.

            Comment

            • _AnonCoward

              #7
              Re: Shutting down GUI apps


              "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
              news:eoqi6o$1vi $1@south.jnrs.j a.net...
              :
              : Stephany Young wrote:
              : >
              : I'm glad you've got it sussed.
              : >
              : It's not 'too simple'. That's exactly what that event is designed
              : for.
              :
              : Agreed.
              :
              : Am I the only one that thinks it "sad" that people regard a
              : well-designed and well-functioning VB feature such as this as being
              : "too simple" in this Brave New World of .Net?

              <sigh>

              It was humor, and slightly self deprecating at that. I had found this
              form method and had considered it but thought I might be overlooking
              something because it seemed too, well, simple or perhaps just a little
              too obvious. I don't like to make assumptions when I code and just
              because a given function may seem at first blush to do what I need, it
              isn't necessary so. I was looking for input from the larger community
              on what approaches other's have taken and any advice on potential
              problems I should be on the look out for.


              Ralf
              --
              --
              ----------------------------------------------------------
              * ^~^ ^~^ *
              * _ {~ ~} {~ ~} _ *
              * /_``>*< >*<''_\ *
              * (\--_)++) (++(_--/) *
              ----------------------------------------------------------
              There are no advanced students in Aikido - there are only
              competent beginners. There are no advanced techniques -
              only the correct application of basic principles.




              Comment

              Working...