Form_Closing + Shutting down Computer

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

    #1

    Form_Closing + Shutting down Computer

    Hi All,

    In my application, every time the user "Close" the form, I cancel the close
    and I put a NotifyIcon in the systray. Here is my code :

    Private myForm_Closing( ... ... ...) Handels MyBase.Closing
    e.Cancel = True
    End sub

    My problem is : When the user try to shut Down his computer, My application
    cannot close, so the computer does not shut down...

    How May I know if the form is closing because the close click the X button
    or because the computer is shutting down ?


    Thx for your help...


    Eddie


  • Ken Tucker [MVP]

    #2
    Re: Form_Closing + Shutting down Computer

    Hi,

    http://msdn.microsoft.com/library/de...ndingtopic.asp

    Ken
    ------------------
    "Eddie" <mathieu.rondea u@videotron.ca> wrote in message
    news:uadLgNuLEH A.3012@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi All,
    >
    > In my application, every time the user "Close" the form, I cancel the
    > close
    > and I put a NotifyIcon in the systray. Here is my code :
    >
    > Private myForm_Closing( ... ... ...) Handels MyBase.Closing
    > e.Cancel = True
    > End sub
    >
    > My problem is : When the user try to shut Down his computer, My
    > application
    > cannot close, so the computer does not shut down...
    >
    > How May I know if the form is closing because the close click the X button
    > or because the computer is shutting down ?
    >
    >
    > Thx for your help...
    >
    >
    > Eddie
    >
    >[/color]


    Comment

    • Eddie

      #3
      Re: Form_Closing + Shutting down Computer

      Thank you Ken...

      It works only if I Start My application with a Form.
      The problem is that I Start My Application without form... Only with a
      NotifyIcon... like this :

      -------------------------------
      Public Sub Main

      Dim oForm as New Form1
      oForm.NotifyIco n.Text = "Test"
      oForm.NotifyIco n.Icon = oForm.Icon
      oForm.NotifyIco n.Visible = True

      Application.Run ()

      End Sub
      -------------------------------

      If I don't start with a Form, the event is not fired...

      Any Ideas ?

      Thanks again...

      Eddie

      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
      news:%23kdvu0uL EHA.1644@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Hi,
      >
      >[/color]
      http://msdn.microsoft.com/library/de...ndingtopic.asp[color=blue]
      >
      > Ken
      > ------------------
      > "Eddie" <mathieu.rondea u@videotron.ca> wrote in message
      > news:uadLgNuLEH A.3012@tk2msftn gp13.phx.gbl...[color=green]
      > > Hi All,
      > >
      > > In my application, every time the user "Close" the form, I cancel the
      > > close
      > > and I put a NotifyIcon in the systray. Here is my code :
      > >
      > > Private myForm_Closing( ... ... ...) Handels MyBase.Closing
      > > e.Cancel = True
      > > End sub
      > >
      > > My problem is : When the user try to shut Down his computer, My
      > > application
      > > cannot close, so the computer does not shut down...
      > >
      > > How May I know if the form is closing because the close click the X[/color][/color]
      button[color=blue][color=green]
      > > or because the computer is shutting down ?
      > >
      > >
      > > Thx for your help...
      > >
      > >
      > > Eddie
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Form_Closing + Shutting down Computer

        * "Eddie" <mathieu.rondea u@videotron.ca> scripsit:[color=blue]
        > It works only if I Start My application with a Form.
        > The problem is that I Start My Application without form... Only with a
        > NotifyIcon... like this :[/color]

        Are you sure you set up a handler? Post the code you used to handle the
        'SessionEnding' event.

        --
        Herfried K. Wagner [MVP]
        <URL:http://dotnet.mvps.org/>

        Comment

        • Eddie

          #5
          Re: Form_Closing + Shutting down Computer

          I tried to set up a handler in many sub...


          ---------------------------------------
          Public Sub Main

          Dim oForm as New Form1
          oForm.NotifyIco n.Text = "Test"
          oForm.NotifyIco n.Icon = oForm.Icon
          oForm.NotifyIco n.Visible = True

          AddHandler Microsoft.Win32 .SystemEvents.S essionEnding, New
          SessionEndingEv entHandler(Addr essOf SessionIsEnding )
          Application.Run ()

          End Sub
          ---------------------------------------


          I also tried to Set up the Handler in the Form_Load Event...

          If I start My Applicatiotion directly with the Form, it works perfectly...



          Any Help will be appreciate...

          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
          news:c75q02$1bm 0$6@ID-208219.news.uni-berlin.de...[color=blue]
          > * "Eddie" <mathieu.rondea u@videotron.ca> scripsit:[color=green]
          > > It works only if I Start My application with a Form.
          > > The problem is that I Start My Application without form... Only with a
          > > NotifyIcon... like this :[/color]
          >
          > Are you sure you set up a handler? Post the code you used to handle the
          > 'SessionEnding' event.
          >
          > --
          > Herfried K. Wagner [MVP]
          > <URL:http://dotnet.mvps.org/>[/color]



          Comment

          Working...