隐藏表单、切换到第二个表单、关闭第二个表单和取消隐藏第一个表单 [英] Hiding a form, switch to a second form, close second form and unhide first form

查看:52
本文介绍了隐藏表单、切换到第二个表单、关闭第二个表单和取消隐藏第一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了所有建议的答案,但似乎没有任何内容符合我的要求.我想从我的主窗体调用第二个窗体,在第二个窗体处于活动状态时隐藏我的主窗体,然后在第二个窗体关闭时取消隐藏主窗体.基本上我想在两种形式之间切换".

I've looked at all the suggested answers and nothing seems to fit what I'm looking for. I want to call a second form from my main form, hide my main form while the second form is active, and then unhide the main form when the second form closes. Basically I want to "toggle" between the two forms.

到目前为止我有:

在我的主要形式中:

private void countClick(object sender, EventArgs e)
{
    this.Hide(); 
    subForm myNewForm = new subForm();
    myNewForm.ShowDialog();
}

在我的第二种形式中,我有:

and in my second form I have:

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

如何让主窗体显示?

推荐答案

ShowDialog 将您的辅助表单作为模态对话框打开,这意味着 MainForm 的代码执行将在该点停止并且您的辅助表单将获得焦点.所以你需要做的就是在你的 ShowDialog 调用之后放一个 this.Show.

ShowDialog opens your secondary Form as Modal Dialog, meaning that the MainForm's code execution will stop at that point and your secondary Form will have the focus. so all that you need to do is put a this.Show after your ShowDialog call.

来自上面的链接:

您可以使用此方法在您的应用程序中显示模态对话框.调用此方法时,直到对话框关闭后才会执行其后面的代码.

You can use this method to display a modal dialog box in your application. When this method is called, the code following it is not executed until after the dialog box is closed.

private void countClick(object sender, EventArgs e)
{
    this.Hide(); 
    subForm myNewForm = new subForm();
    myNewForm.ShowDialog();
    this.Show();
}

这篇关于隐藏表单、切换到第二个表单、关闭第二个表单和取消隐藏第一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆