472,981 Members | 1,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 software developers and data experts.

catching close button

How can I prevent the big close button in the top of the window from
closing the window?
I want to have and "are you sure?" confirmation so the user must press
"Yes" before the program ends. Right now, I've tried catching the
FormClosing and FormClosed events. The message box appears at the right
time, but since the form is already closing, it doesn't matter if the
user presses "Yes" or "No". how do I cancel the FormClosing?

Nov 30 '06 #1
5 2559

lord.zol...@gmail.com wrote:
How can I prevent the big close button in the top of the window from
closing the window?
I want to have and "are you sure?" confirmation so the user must press
"Yes" before the program ends. Right now, I've tried catching the
FormClosing and FormClosed events. The message box appears at the right
time, but since the form is already closing, it doesn't matter if the
user presses "Yes" or "No". how do I cancel the FormClosing?

nevermind... solution is e.Cancel (to stop the Closing event) and
e.CloseReason.
(e is the FormClosing eventarg)

Nov 30 '06 #2
Just in case you (or other readers) may want to know about how to trap
the messages from the title bar buttons (maximize/minimize, restore,
and exit) then here's a post from Herfried Wagner a while back that may
help:

Thanks,

Seth Rowe

------------------------------------------------------
Is there a way I can get into a form's close/minimize/maximize events when
those buttons (the 3 small squared button in the upper right corner of a
form) are clicked?
\\\
Private Const WM_SYSCOMMAND As Int32 = &H112

Private Const SC_MAXIMIZE As Int32 = &HF030
Private Const SC_MINIMIZE As Int32 = &HF020
Private Const SC_RESTORE As Int32 = &HF120
Private Const SC_CLOSE As Int32 = &HF060

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
Select Case m.WParam.ToInt32()
Case SC_MAXIMIZE
Debug.WriteLine("Form gets maximized.")
Case SC_MINIMIZE
Debug.WriteLine("Form gets minimized.")
Case SC_RESTORE
Debug.WriteLine("Form gets restored.")
Case SC_CLOSE
Debug.WriteLine("Form gets closed.")
End Select
End If
MyBase.WndProc(m)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

------------------------------------------------------

lo*********@gmail.com wrote:
lord.zol...@gmail.com wrote:
How can I prevent the big close button in the top of the window from
closing the window?
I want to have and "are you sure?" confirmation so the user must press
"Yes" before the program ends. Right now, I've tried catching the
FormClosing and FormClosed events. The message box appears at the right
time, but since the form is already closing, it doesn't matter if the
user presses "Yes" or "No". how do I cancel the FormClosing?


nevermind... solution is e.Cancel (to stop the Closing event) and
e.CloseReason.
(e is the FormClosing eventarg)
Nov 30 '06 #3
In the form_closing event

set 'cancel = true'
<lo*********@gmail.comwrote in message
news:11********************@l39g2000cwd.googlegrou ps.com...
How can I prevent the big close button in the top of the window from
closing the window?
I want to have and "are you sure?" confirmation so the user must press
"Yes" before the program ends. Right now, I've tried catching the
FormClosing and FormClosed events. The message box appears at the right
time, but since the form is already closing, it doesn't matter if the
user presses "Yes" or "No". how do I cancel the FormClosing?

Nov 30 '06 #4
Rowe,

Not in this case, the e.cancel is in this exit question in my idea the best.

Cor

"rowe_newsgroups" <ro********@yahoo.comschreef in bericht
news:11**********************@j72g2000cwa.googlegr oups.com...
Just in case you (or other readers) may want to know about how to trap
the messages from the title bar buttons (maximize/minimize, restore,
and exit) then here's a post from Herfried Wagner a while back that may
help:

Thanks,

Seth Rowe

------------------------------------------------------
>Is there a way I can get into a form's close/minimize/maximize events
when
those buttons (the 3 small squared button in the upper right corner of a
form) are clicked?

\\\
Private Const WM_SYSCOMMAND As Int32 = &H112

Private Const SC_MAXIMIZE As Int32 = &HF030
Private Const SC_MINIMIZE As Int32 = &HF020
Private Const SC_RESTORE As Int32 = &HF120
Private Const SC_CLOSE As Int32 = &HF060

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
Select Case m.WParam.ToInt32()
Case SC_MAXIMIZE
Debug.WriteLine("Form gets maximized.")
Case SC_MINIMIZE
Debug.WriteLine("Form gets minimized.")
Case SC_RESTORE
Debug.WriteLine("Form gets restored.")
Case SC_CLOSE
Debug.WriteLine("Form gets closed.")
End Select
End If
MyBase.WndProc(m)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

------------------------------------------------------

lo*********@gmail.com wrote:
>lord.zol...@gmail.com wrote:
How can I prevent the big close button in the top of the window from
closing the window?
I want to have and "are you sure?" confirmation so the user must press
"Yes" before the program ends. Right now, I've tried catching the
FormClosing and FormClosed events. The message box appears at the right
time, but since the form is already closing, it doesn't matter if the
user presses "Yes" or "No". how do I cancel the FormClosing?


nevermind... solution is e.Cancel (to stop the Closing event) and
e.CloseReason.
(e is the FormClosing eventarg)

Dec 1 '06 #5
Not in this case, the e.cancel is in this exit question in my idea the best.

I know - whenever I see a post about catching the close button I figure
the next question will be "ok, now how do I trap the other buttons?." I
figured posted it here would help out someone searching the archives
(well, if any one does that anymore :-) )

Thanks,

Seth Rowe
Cor Ligthert [MVP] wrote:
Rowe,

Not in this case, the e.cancel is in this exit question in my idea the best.

Cor

"rowe_newsgroups" <ro********@yahoo.comschreef in bericht
news:11**********************@j72g2000cwa.googlegr oups.com...
Just in case you (or other readers) may want to know about how to trap
the messages from the title bar buttons (maximize/minimize, restore,
and exit) then here's a post from Herfried Wagner a while back that may
help:

Thanks,

Seth Rowe

------------------------------------------------------
Is there a way I can get into a form's close/minimize/maximize events
when
those buttons (the 3 small squared button in the upper right corner of a
form) are clicked?
\\\
Private Const WM_SYSCOMMAND As Int32 = &H112

Private Const SC_MAXIMIZE As Int32 = &HF030
Private Const SC_MINIMIZE As Int32 = &HF020
Private Const SC_RESTORE As Int32 = &HF120
Private Const SC_CLOSE As Int32 = &HF060

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND Then
Select Case m.WParam.ToInt32()
Case SC_MAXIMIZE
Debug.WriteLine("Form gets maximized.")
Case SC_MINIMIZE
Debug.WriteLine("Form gets minimized.")
Case SC_RESTORE
Debug.WriteLine("Form gets restored.")
Case SC_CLOSE
Debug.WriteLine("Form gets closed.")
End Select
End If
MyBase.WndProc(m)
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

------------------------------------------------------

lo*********@gmail.com wrote:
lord.zol...@gmail.com wrote:
How can I prevent the big close button in the top of the window from
closing the window?
I want to have and "are you sure?" confirmation so the user must press
"Yes" before the program ends. Right now, I've tried catching the
FormClosing and FormClosed events. The message box appears at the right
time, but since the form is already closing, it doesn't matter if the
user presses "Yes" or "No". how do I cancel the FormClosing?
nevermind... solution is e.Cancel (to stop the Closing event) and
e.CloseReason.
(e is the FormClosing eventarg)
Dec 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ron L | last post by:
I have an MDI application with a number of child windows. In each child window I am catching the Closing event and having the child window decide if it should set cancel to true. The intent here...
4
by: stb | last post by:
I have an empty asp:table on a form. Rows and cells in the rows are added programatically. At the end of each row, there is a cell with a button inside it. How do I catch the button's click...
2
by: Eric Lilja | last post by:
Hello, consider this complete program: #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Hanna {
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
1
by: Matt Brown - identify | last post by:
Hello, I, as well as suspecting many others, am having an issue when I attempt to enter sleep mode in Vista. If any program is connected to the internet (AOL Instant Messenger for instance),...
2
by: toringe | last post by:
Hi I try to connect to a cardreader from a VB.NET 2003 application. The cardreader manufacturer has provided an OCX to access the reader trough. The OCX sends status messages back by using...
2
by: =?Utf-8?B?TmVldGE=?= | last post by:
Hi, I creating a console application. In that I want to catch the cancel event of the console application .Please guide me in this.I figured out that I will have to attach event to the...
3
by: =?Utf-8?B?SnVzdCBjbG9zZSB5b3VyIGV5ZXMgYW5kIHNlZQ== | last post by:
Hello All I am trying to catch a right button down event for a control before the form sends it to this control; I tried to do that through overriding the WndProc But it fails! Is there any way...
2
by: Bruce | last post by:
Hello, I have a form in an Access 2003 application which opens maximized. Its CloseButton property is set to false. On this form I have a command button that opens a report in preview mode. ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.