473,805 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6889
yh****@gmail.co m 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******** **********@news fe6-gui.ntli.net...
yh****@gmail.co m 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.co m 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.ToInt3 2()
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_newsgroup s" <ro********@yah oo.comwrote in message
news:11******** **************@ k78g2000cwa.goo glegroups.com.. .
On Feb 24, 10:52 am, yhl...@gmail.co m 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.ToInt3 2()
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
12298
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 development environment. I have an applicatin error logger which shows this error occuring (in the stack trace dump) but it again occurs at different locations in the code and occurs inconsistently. If anyone knows why it occurs or what can be...
6
3256
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. Is there anyway how to catch this kinds of exceptions? Can I put somewhere a
0
1478
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 from DataPath, I get the following error- message when trying to edit a Form (design-mode): "Error creating window handle".
1
3925
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 occurs during a this.PointToScreen( newPos )-call, and "this" is referencing a instantiated Form class.... newPos is of class Point.
4
1909
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 that request? IHttpHandler or IHttpModule? Thanks! --
3
8352
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 the development environment. I have an applicatin error logger which shows this error occuring (in the stack trace dump) but it again occurs at different locations in the code and occurs inconsistently. My application is a windows forms...
1
8613
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 the maze, it appends each step it takes to the StringBuilder. When the maze is solved, the user can click a menu item to display the results. When the menu item is clicked, I set the TextBox Text value using the StringBuilder's ToString()...
6
7210
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 OnClick operation on the server side if the user had clicked Ok (as opposed to Cancel) on the pop-up dialog. I know I can do this all myself with JavaScript, but I was just wondering if any such functionality is already built-in in ASP.NET 2.0 so that...
3
5709
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 pressing Enter. But, of course, DoubleClick doesn't automatically handle that. Is there any way to handle ALL standard UI at once, rather than checking for DoubleClick and for Enter press manually? Zytan
2
9129
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 not able to find out the root cause of it. Can somebody help me out? 2. How can I find the total window handle count? If I open crash dump and run the command !handle, it provides me 792 handle count. Further investigation (!DumpHeap -type...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10361
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.