本文介绍了关闭表单,然后调用另外一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要关闭目前的形式我在(MainForm的),然后打开第二个(表)。

I want to close the current form I'm on (MainForm) and then opening a second one (Form).

我试过:

private void buttonStartQuiz_Click(object sender, EventArgs e)
{
    this.Close();

    Form2 form2 = new Form2();
    form2.ShowDialog();
}

或者添加 this.Close(); form2.ShowDialog()也不起作用。

任何提示?

编辑:还不如补充说,通过添加 this.Close() form2.ShowDialog()它只有关闭当我关闭新形式。
如果让我选择 form2.Show()而是立即关闭两种形式。

Might as well add that by adding this.Close() after form2.ShowDialog() it close only when I close the new form.If I choose form2.Show() instead it immediately closes both of the forms.

推荐答案

修改

this.Close();

要:

this.Hide();

由于不能关闭应用程序主窗口,并希望后,应用程序运行。
您必须隐藏的主要形式或更改主窗口谁仍然打开的窗口。

Because you can't Close Main Application window and want to application runs after it.You must hide main form or change main window to window who was still opened.

在这种情况下,你必须关闭后 ShowDialog的主窗口()被终结。
然后,你必须添加该按钮事件函数结束 this.Close()

In this case you must close main window after ShowDialog() was ended.Then you must add on the end of this button event function this.Close()

您code $新C $ c是:

Your code new code is:

private void buttonStartQuiz_Click(object sender, EventArgs e)
    {
        // hide main form
        this.Hide();

        // show other form
        Form2 form2 = new Form2();
        form2.ShowDialog();

        // close application
        this.Close();
    }

这篇关于关闭表单,然后调用另外一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 07:12