本文介绍了FormClosing e.cancel = true无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C#Windows应用程序.
我有我的主要GUI.当用户单击按钮时,我将启动一个新线程并打开一个新对话框(TestForm).
对话框表单包含以下代码:
C# windows application.
I have my main gui. When a user clicks a button I start a new thread and open a new dialog (TestForm).
the dialog form consists of this code:
private void TestForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
该线程仅包含
The thread only consists of
private static void startTestThread()
{
test.ShowDialog();
MessageBox.Show("Got Here");
}
测试定义如下:
where test is defined as follows:
public static TestForm test = new TestForm();
问题在于,当窗体关闭时,它确实会碰到关闭事件,并将e.cancel设置为true,但是随后对话框关闭,出现了显示此消息的MessageBox且线程死了.
我需要隐藏表格,然后继续执行线程.
谢谢:)
The problem is that when the form is closing, it does hit the closing event and set e.cancel to true, but then the dialog closes, MessageBox showing this comes up and the thread dies.
I need the form to just hide and the thread to continue.
Thanks :)
推荐答案
这篇关于FormClosing e.cancel = true无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!