formclosing

Is DoEvents() also evil in FormClosing?

佐手、 提交于 2019-12-06 04:35:46
On a different question I suggested to use private void Form1_FormClosing(object sender, FormClosingEventArgs e) { while (processingLock) Application.DoEvents(); } in the FormClosing event (with processingLock becoming false immediately after a lengthy calculation was done). It should serve the purpose to have the application close down in an orderly manner and the original poster didn't use threads. On my suggested answer somebody commented that DoEvents is never good, providing this link: Use of Application.DoEvents() I read and (I think) understood the issue. In my opinion (which is still

MessageBox on Form Closing

让人想犯罪 __ 提交于 2019-12-04 01:17:34
问题 I'm use this code for question before closing the application, but it is not working correctly. My code is as below. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { DialogResult dlgresult = MessageBox.Show("Exit or no?", "My First Application", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dlgresult == DialogResult.No) { e.Cancel = true; } else { Application.Exit(); } } 回答1: You don't need to explicitly call Application.Exit() since you are in the

“e.Cancel ” in formclosing Event

二次信任 提交于 2019-12-02 23:40:34
When using the FormClosing event, why does the code e.Cancel = true; work, but new CancelEventArgs().Cancel = true; does not work? private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; new CancelEventArgs().Cancel = true; } The event is raised by the Winforms plumbing code. The only way it can see that the custom event handler wants to alter the default behavior is through the e object. Creating a new CancelEventArgs object has no side-effects that the plumbing can detect. There's something else wrong, events are raised for the benefit of external code,

C# MDI Parent detect when MDI Child is closing?

你离开我真会死。 提交于 2019-12-01 17:39:22
问题 I'm attempting to detect, on the MDI parent, when my MDI child form closes, and react accordingly. The MDI parent shouldn't do anything until the MDI child closes. Here is my code, I'm unsure as to what I'm doing wrong, but the form closed event method I added is never being called... The following code is in the MDI parent class, if that wasn't obvious. private void keyValidation() { if (Properties.Settings.Default.Unlock == true) return; else { menu.Enabled = false; statusStrip.Enabled =

How to prevent Closing and Disposing of a winform in the FormClosing event?

百般思念 提交于 2019-12-01 05:46:35
问题 This question may seem like a duplicate, but I just ran in to this issue while I was testing my program and I am kind of confused as to how you solve it. I have a winform and it has a form closing event. In the event, I pop open a messagebox asking the user, "Are you sure you want to close the window?." If they pushed yes button, the application closes window and prevents it from being disposed as expected. So, I can open it again. However, if they pushed no button, it still closes the window

VB.NET: Abort FormClosing()

让人想犯罪 __ 提交于 2019-12-01 03:52:08
I have a code snippet that I want to run when the app is closing. So, I used FormCLosing event. But now i wanna place a confirmation message for exiting. Like, if the user clicks the Exit( X ) button, there'll be a prompt, if he clicks NO, then the app will not close and revert to previous state. Now I find that hard to achieve using FormClosing event. because it'll get executed no matter what button the user clicks. Any remedy for that? I mean, I need an even like ExitButtonPressed() .. You could try something like Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System

How do I prevent a form object from disposing on close?

烈酒焚心 提交于 2019-11-29 05:40:40
I am using an MDIParent Form. When I close its child, the object of the child disposes. Is there a way to set child visibility to false instead of disposing? By default, when you close a form, it will be disposed. You have to override the Closing event to prevent it, for example: // Use this event handler for the FormClosing event. private void MyForm_FormClosing(object sender, FormClosingEventArgs e) { this.Hide(); e.Cancel = true; // this cancels the close event. } You can cancel the close event and hide instead. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e

Get the application closing event

笑着哭i 提交于 2019-11-28 23:29:13
How to get to the application closing event? I want to get application to save all unsaved operations or show the user a message "Are you sure about closing without saving all data?" something like this. If this will be helpful - the application is a SingleFrameAplication using Swing. You could use a shutdown hook . It works for Swing, AWT and even console applications. Example: Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { //do your stuff } }); mKorbel You have to add WindowListener to your JFrame / JDialog , about closing event is there method public void

Window close events in a winforms application

可紊 提交于 2019-11-28 01:19:09
I am looking to prompt the user to save data when they close a form window in a winforms application. I can't figure out how to trigger the prompt to the user, should they click the red box at the top right corner of the form. My application currently has a boolean flag, that is set to True on textchanged event. So I will only need to check for the boolean value in whatever event is trigger by the red box. Any advice? You need to handle the FormClosing event . This event is raised just before the form is about to be closed, whether because the user clicked the "X" button in the title bar or

How do I prevent a form object from disposing on close?

こ雲淡風輕ζ 提交于 2019-11-27 23:14:51
问题 I am using an MDIParent Form. When I close its child, the object of the child disposes. Is there a way to set child visibility to false instead of disposing? 回答1: By default, when you close a form, it will be disposed. You have to override the Closing event to prevent it, for example: // Use this event handler for the FormClosing event. private void MyForm_FormClosing(object sender, FormClosingEventArgs e) { this.Hide(); e.Cancel = true; // this cancels the close event. } 回答2: You can cancel