473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Handle the "X" button

Hi

I would like to know how can I handle the event that the user press
the red button "X" (The button which suppose to close the program) ?
I tried to double click on it (in the form editor) but nothing
happened...
Thanks
Yhlove

Feb 24 '07 #1
4 6869
yh****@gmail.com wrote:
I would like to know how can I handle the event that the user press
the red button "X" (The button which suppose to close the program) ?
I tried to double click on it (in the form editor) but nothing
happened...
Try handling the FormClosing event of the form if you want to know the user
closed the window but before it actually closes (also giving you an
opportunity to cancel the closure if you wish), and/or the FormClosed event
(which fires once it actually has closed).

HTH,

--

(O)enone
Feb 24 '07 #2
In addition, when you then want to cancel it, set in that event
e.cancel=true

Cor

"(O)enone" <oe****@nowhere.comschreef in bericht
news:Iu******************@newsfe6-gui.ntli.net...
yh****@gmail.com wrote:
>I would like to know how can I handle the event that the user press
the red button "X" (The button which suppose to close the program) ?
I tried to double click on it (in the form editor) but nothing
happened...

Try handling the FormClosing event of the form if you want to know the
user closed the window but before it actually closes (also giving you an
opportunity to cancel the closure if you wish), and/or the FormClosed
event (which fires once it actually has closed).

HTH,

--

(O)enone

Feb 24 '07 #3
On Feb 24, 10:52 am, yhl...@gmail.com wrote:
Hi

I would like to know how can I handle the event that the user press
the red button "X" (The button which suppose to close the program) ?
I tried to double click on it (in the form editor) but nothing
happened...

Thanks
Yhlove
Just in case the other mentioned events don't do what you need/want,
here's a snippet from Herfried Wagner that can be used to trap the
windows messages that correspond to the 3 buttons on the form (close,
minimize, restore down)

Oh, please no one yell at me for posting this here, I realize in 99%
of situations the FormClosing/FormClosed events will be more than
sufficient. This is mainly for the benefit of people who might be
searching the archives for "Handle X button" that need to use a
wndproc override (you know, the other 1%)

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/>

Feb 24 '07 #4

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
On Feb 24, 10:52 am, yhl...@gmail.com wrote:
>Hi

I would like to know how can I handle the event that the user press
the red button "X" (The button which suppose to close the program) ?
I tried to double click on it (in the form editor) but nothing
happened...

Thanks
Yhlove

Just in case the other mentioned events don't do what you need/want,
here's a snippet from Herfried Wagner that can be used to trap the
windows messages that correspond to the 3 buttons on the form (close,
minimize, restore down)

Oh, please no one yell at me for posting this here, I realize in 99%
of situations the FormClosing/FormClosed events will be more than
sufficient. This is mainly for the benefit of people who might be
searching the archives for "Handle X button" that need to use a
wndproc override (you know, the other 1%)

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/>
Thanks for posting this. It's really useful information.

Robin S.
Feb 26 '07 #5

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

Similar topics

1
by: viditm | last post by:
Hi I keep getting the error "Error Creating Windows Handle" in my application and different places in the code. This occurs only to certain users. Its very random and cannot be reproduced in the...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
0
by: Arne Styve | last post by:
Hi, I am developing a small application in C# where I call a C API. This application is to control some videocards from DataPath. After installing the graphichs card and the videoswitch cards...
1
by: Arne | last post by:
Hi, I keep getting "Error creating window handle." now and then while running my C# application. I've tried to figure out why, but I'm stuck. What is the usual cause of this error ? The error...
4
by: davidw | last post by:
For example, I have a virtual directory - "wfile", I would like user access http://mysite/wfile, but I want to handle it with my own code instead of turn on "Directory Browsing", how can I capture...
3
by: Vidit | last post by:
Hi I keep getting the error "Error Creating Windows Handle" in my application and different places in the code. This occurs only to certain users. Its very random and cannot be reproduced in...
1
by: Flack | last post by:
Hey guys, Here is whats happening. I have a StringBuilder, a TextBox, and a TabControl with one TabPage. On my main form, I created and displayed a fairly big maze. While the app is solving...
6
by: Alex Maghen | last post by:
Let's say I have a web forms button which performs a Delete or something. I'd like a click on the button to pop an "Are you Sure" dialog on the client side and then only execute the button's...
3
by: Zytan | last post by:
I can handle DoubleClick on a ListBox to respond, not when the selection changes, but when you double click one to invoke an action. This is the same as using the keys to move the selection, then...
2
by: rvarshney | last post by:
Hi All, Sometimes my application crashes with the exception Exception type: System.ComponentModel.Win32Exception Message: Error creating window handle. My Question to you guys are: 1. I am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.