|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Capturing Close EventsThe 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 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 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. Show quoteHide quote > 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
Other interesting topics
qualify base class members from derived class
Copying Data Instead of Memory Addresses Write attributes Database help Srange Object error General question about C# Newbie question - accessing ArrayList members via index. Getting list of printer paper names / sizes: calling DeviceCapabilities from C# looking at a C++ dll with a .NET wrapper. need help. Maximize Box and HelpButton |
|||||||||||||||||||||||