473,226 Members | 1,541 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,226 software developers and data experts.

Handle the form closing when the user clicks on the "X" button (form caption bar)

Hi,
suppose that you have a C# form with two buttons, that are the
classical "btnOk" and "btnCancel" (besides them, of course in
the form there can be many other controls).
When the user clicks on btnOk, the program makes some confirm
operations and closes the form.
When the user clicks on btnCancel, the program makes some cancel
operations and closes the form.
My problem is that, when the user clicks on the "X" button of the
form caption bar, the form simply closes, while I would like that the
program made the same cancel operations as in the btnCancel click case.
I have discovered that the Form class has the "OnClosing" event
handler (that is executed when the form closes), but I can't insert
the cancel statements in its code (it is executed when the user clicks
on btnOk and btnCancel too, so the program would execute two times the
cancel operations or first the confirm operations and then the cancel
ones).
Is there a form event handler for the "X" form button click?
Or is there a form property that allows to associate the "X" form
button click to a button inside the form (btnCancel, in this case)?
Otherwise, can you propose me a simple way to handle this situation?
Thank you very much

Nov 10 '06 #1
2 3260
In the eventargs for OnClosing you'll find a cancel property. If you
set that to true the form will not close. Create a member variable set
to true and set it to false when the user clicks either the cancel or
ok buttons.

That's not the tidiest route, but it will work.

polocar wrote:
Hi,
suppose that you have a C# form with two buttons, that are the
classical "btnOk" and "btnCancel" (besides them, of course in
the form there can be many other controls).
When the user clicks on btnOk, the program makes some confirm
operations and closes the form.
When the user clicks on btnCancel, the program makes some cancel
operations and closes the form.
My problem is that, when the user clicks on the "X" button of the
form caption bar, the form simply closes, while I would like that the
program made the same cancel operations as in the btnCancel click case.
I have discovered that the Form class has the "OnClosing" event
handler (that is executed when the form closes), but I can't insert
the cancel statements in its code (it is executed when the user clicks
on btnOk and btnCancel too, so the program would execute two times the
cancel operations or first the confirm operations and then the cancel
ones).
Is there a form event handler for the "X" form button click?
Or is there a form property that allows to associate the "X" form
button click to a button inside the form (btnCancel, in this case)?
Otherwise, can you propose me a simple way to handle this situation?
Thank you very much
Nov 10 '06 #2
Hi,

In the 2.0 framework use the FormClosing event instead of Closing, which is
now obsolete because it isn't raised when Application.Exit is called. Same
goes for the FormClosed and Closed events.

"Form.FormClosing Event"
http://msdn2.microsoft.com/en-us/lib...rmclosing.aspx

--
Dave Sexton

"DeveloperX" <nn*****@operamail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
In the eventargs for OnClosing you'll find a cancel property. If you
set that to true the form will not close. Create a member variable set
to true and set it to false when the user clicks either the cancel or
ok buttons.

That's not the tidiest route, but it will work.

polocar wrote:
>Hi,
suppose that you have a C# form with two buttons, that are the
classical "btnOk" and "btnCancel" (besides them, of course in
the form there can be many other controls).
When the user clicks on btnOk, the program makes some confirm
operations and closes the form.
When the user clicks on btnCancel, the program makes some cancel
operations and closes the form.
My problem is that, when the user clicks on the "X" button of the
form caption bar, the form simply closes, while I would like that the
program made the same cancel operations as in the btnCancel click case.
I have discovered that the Form class has the "OnClosing" event
handler (that is executed when the form closes), but I can't insert
the cancel statements in its code (it is executed when the user clicks
on btnOk and btnCancel too, so the program would execute two times the
cancel operations or first the confirm operations and then the cancel
ones).
Is there a form event handler for the "X" form button click?
Or is there a form property that allows to associate the "X" form
button click to a button inside the form (btnCancel, in this case)?
Otherwise, can you propose me a simple way to handle this situation?
Thank you very much

Nov 10 '06 #3

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

Similar topics

1
by: David Bradbury | last post by:
Hi On my form, as soon as the user clicks my submit button a message pops up saying "Form processing" as the form submits. This is fine as long as the user only clicks the submit button once....
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."...
3
by: David | last post by:
Hi, I need a button shown for each record (cont. form) with specific captions on each. I have a notes form for each record. When a user presses the button they can read the notes. I want to...
7
by: al | last post by:
Greetings all, I use request.form("textbox1") to get data back to page, dim str as string str = request.form("textbox1").tostring But str is always empty after refresh???? I use asp.net...
4
by: Nacho Nachev | last post by:
This may sound like a silly question, but what is the appropriate way to handle form double submitting in ASP.NET. Page expiration, etc? I am looking for a way to handle this in some cetral point...
2
by: jayasabari | last post by:
Hai, When button is clicked, then i have to prevent the execution of one function in page load. can you give any suggestion please. With Regards, K.Jayasabari
0
by: vincent90152900 | last post by:
I like to Customize the layout of a CreateUserWizard component and I would like to chnge the “Create User” button to an ImageButton. How to do that? Following is my codes. ...
3
by: Alexio | last post by:
I need to enter a date into a text field when form is loaded. However I need this date to be static when the form is opened at a later date. I have the text box set to readonly. Will this be...
4
by: robertallenpayne | last post by:
I have been asked to develop an application in Access for work. This application must have a simple user interface because the folks using it are not "database people" - their words, not mine. ...
9
by: ghjk | last post by:
change the background image when Button Click ====================================== I' developing site with php and postgres. It has menus list in the left side. and all are images(jpg) EX:Add...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.