Question Syntax Needed, stop form closing?

Joined
Mar 31, 2008
Messages
8
Programming Experience
1-3
OK, here is the scenario.
I am creating a cash register program for a coffee shop.
Now--one major problem the owner is having.
The Employees tend to close the form (VIA the Exit_click code procedure, correct?)
They will lose that day's information, because it saves the base information at the end of the day in a CSV file.
Now the problem I have is this:
Since I cannot prevent them from closing it, there has got to be some way to access a new form when they click close. I have created this form, and made it password protected, so that only password holders may close the program.

BUT

The close procedure doesn't want to stop. At All. I need the auto procedure to be interuppted, and the Close button needs to be re-routed to this logout form. Does anyone have any advice? I REALLY NEED THIS ASAP!!!!!!

Please contact me at my personal E-Mail, [***email removed***], for the reason that I cannot access this forum through a dam site blocker at the computer i will be working on later.:mad: Thank You in advance. :)
 
Last edited by a moderator:
Try something like this, it will make the X button just minimize.

I think its a more elegant solution for you.

Private Const WM_QUERYENDSESSION As Integer = &H11
Private Const WM_ENDSESSION As Integer = &H16

Private _systemShutdown As Boolean = False

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' Listen for operating system messages
If m.Msg = WM_QUERYENDSESSION Or m.Msg = WM_ENDSESSION Then
_systemShutdown = True
End If

' Handle the message
MyBase.WndProc(m)
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not _systemShutdown = True Then
_systemShutdown = False
e.Cancel = True
Me.WindowState = FormWindowState.Minimized
Else
Me.Dispose()
End If
End Sub
 
Please contact me at my personal E-Mail, [***email removed***], for the reason that I cannot access this forum through a dam site blocker at the computer i will be working on later.:mad: Thank You in advance. :)
If you can provide information: please PM
(And please, don't waste my time with fan mail... LOL :cool:)
Email address was removed to protect your privacy and forum interests. Forums exist for sharing problems and solutions for the benefit of all. You can use forum PM for private messaging too (may not apply until activity limit). If you are unable to use the forums because of computer malfunction you need to fix your computer.
 
That might be good for a different project... because the need to close the program every day, at the end of the day, so it can't just minimize... Is there any way to remove it, then like put my own as a button or something?:confused:
 
Since I cannot prevent them from closing it, there has got to be some way to access a new form when they click close.
You can handle FormClosing event to inspect why the form is closing, cancel the close, and do other things when this happens. See what e parameter of event has to offer.
 
You can handle FormClosing event to inspect why the form is closing, cancel the close, and do other things when this happens. See what e parameter of event has to offer.
That sounds great, but could you share a code snippet or something? I have no idea what i'm doing in this regard.
 
I have no idea what i'm doing in this regard.
Go to the forms Properties window and click the Events button, locate FormClosing event and doubleclick it to have the event handler generated.
Or in code view use the objects/events combos at top to do the same.
 
Back
Top