473,397 Members | 2,028 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,397 software developers and data experts.

Capturing Close Events

Hi

The application I am working on has a starting screen with some
configuration choices and the following:
- OK button
- QUIT button
- x button in the Control/System menu box (top right corner)

The user may quit the application by pressing 'QUIT' or x, or the user
may continue with the application by pressing 'OK'. In both cases,
the form is closed.

You can prboably see where I am going here ... In the form closing
event, I want to be able to capture if the user has :
- pressed OK; or
- clicked x or clicked QUIT (both x and QUIT are handled exactly the
same way)

At the moment I am storing a boolean variable
'CloseRequestSentFromOKbutton' and it works, but surely there must be
a better way?

Thanks
Orekin
Nov 17 '05 #1
2 1696
Orekin,

It is the same as your solution however looks in my opinion more elegant.

\\\
private void button1_Click(object sender,
System.EventArgs e)
{
this.Tag = "button1";
this.Close();
}
private void FormClosing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if ((string) this.Tag == "button1")
MessageBox.Show("button1");
}
///
I hope this helps anyhow.

cor
Nov 17 '05 #2
Hi,

It look as a simple modal form (ShowDialog()) for me.

Why do not set:
btnOK.DialogResult=DialogResult.OK;
btnQuit.DialogResult=DialogResult.Cancel;

In main form you've got to show this form by ShowDialog()
and check it result. If it return OK then show main form
else close main form.

HTH
Marcin

PS: Catching close event is not good choice in modal form.
Hi

The application I am working on has a starting screen with some
configuration choices and the following:
- OK button
- QUIT button
- x button in the Control/System menu box (top right corner)

The user may quit the application by pressing 'QUIT' or x, or the user
may continue with the application by pressing 'OK'. In both cases,
the form is closed.

You can prboably see where I am going here ... In the form closing
event, I want to be able to capture if the user has :
- pressed OK; or
- clicked x or clicked QUIT (both x and QUIT are handled exactly the
same way)

At the moment I am storing a boolean variable
'CloseRequestSentFromOKbutton' and it works, but surely there must be
a better way?

Thanks
Orekin

Nov 17 '05 #3

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

Similar topics

5
by: Fly Girl | last post by:
Gurus needed! I'm trying to use a Word class object in order to capture events in Word. Here's what I have, but the event code appWord_BeforeDocumentSave... doesn't ever fire. In a Class Module...
1
by: Mohit Sachdeva | last post by:
Hello folks. I want my app to process windows events first, so that it has some kind of a "global hook". The scenario is - i want my app to process all messages for "F3" key (or any other key for...
1
by: Rick | last post by:
Assuming proper authentication, does the framework offer a way to capture Windows Server 2003 system security events, as found in the event viewer log files? I'd like to be able to write some...
3
by: PJ6 | last post by:
I'm apparently not understanding something. I want to capture some user events in a web control I'm inheriting from, such as a table cell or a button. The code below doesn't work, the attributes...
2
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
2
by: jbigham | last post by:
Hello, I'd like to capture key events using javascript, but don't want to process such events when the user is typing into an input box or into a textarea. As an example, gmail has a feature...
1
by: beachdog | last post by:
I'm using Visual Studio/C# to build a GUI program, and using a third party component. This third party component isn't behaving as expected in response to some window/mouse events, and I would...
0
by: Hari | last post by:
Hi, I am creating a win app that hosts a web browser control in C#. The web browser renders some local html page. I need to capture the events on that page. I know this can be done with DOM. But...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.