Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

restrict windows shutdown

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
0
0
DE
I have a program in which if no of hours worked in a day is less than 8 hrs, the system should not shutdown. I have used the following code,

In formclosing event, i have written,

e.cancel=true

It is not allowing the system to shutdown or log off nut it is showing the "End program" message anf if "End now" is pressed, the system is getting shut down. Hoe to prevent the "End program message"?
 

Maybe the CloseReason property can help. It is accessed via the System.Windows.Forms.FormClosingEventArgs (e) in the same way as e.Cancel.

The CloseReasons are:

CloseReason.ApplicationExitCall
CloseReason.FormOwnerClosing
CloseReason.MdiFormClosing
CloseReason.None
CloseReason.TaskManagerClosing
CloseReason.UserClosing
CloseReason.WindowsShutDown


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Where should i use the close reasons in coding
 

In the FormClosing event. It is a property of the System.Windows.Forms.FormClosingEventArgs that is represented as the "e" parameter in the event handler's signature. Use it like this:

If e.CloseReason = CloseReason.UserClosing Then
'do something
End If

Again, I'm not sure which of the CloseReason you would use, or even if this will help with your issue.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top