Form_Closing + Shutting down Computer

E

Eddie

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
 
E

Eddie

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.NotifyIcon.Text = "Test"
oForm.NotifyIcon.Icon = oForm.Icon
oForm.NotifyIcon.Visible = True

Application.Run()

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

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

Any Ideas ?

Thanks again...

Eddie
 
H

Herfried K. Wagner [MVP]

* "Eddie said:
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 :

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

Eddie

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


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

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

AddHandler Microsoft.Win32.SystemEvents.SessionEnding, New
SessionEndingEventHandler(AddressOf 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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top