Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 阻止直到窗体关闭?Winforms_C#_Winforms - Fatal编程技术网

C# 阻止直到窗体关闭?Winforms

C# 阻止直到窗体关闭?Winforms,c#,winforms,C#,Winforms,我有一个启动formB的表单。我想把forma藏起来,直到formb关闭。可能会有变化formb是由formC和其他人打开的,所以我不能仅仅创建一个新表单。有没有办法启动formB、隐藏和阻止直到关闭?这样就可以了 this.Visible = false; using (formB as new FormB()) formB.ShowDialog(this); this.Visible = true; 您可以使用OnActivate事件隐藏所有者,使用Dispose事件显示所有者。即

我有一个启动formB的表单。我想把forma藏起来,直到formb关闭。可能会有变化formb是由formC和其他人打开的,所以我不能仅仅创建一个新表单。有没有办法启动formB、隐藏和阻止直到关闭?

这样就可以了

this.Visible = false;
using (formB as new FormB())
    formB.ShowDialog(this);
this.Visible = true;

您可以使用
OnActivate
事件隐藏所有者,使用
Dispose
事件显示所有者。即使未从另一个表单调用表单_b,此解决方案仍然有效:

表格x中的代码:

FormB f = new FormB();
f.Show(this);
表格b中的代码

this.Activated += new System.EventHandler(this.HideOwner);
private void HideOwner(object sender, EventArgs e)
{
    if (this.Owner != null) this.Owner.Hide();
}

protected override void Dispose(bool disposing)
{
    if (this.Owner != null) this.Owner.Show();
    if (disposing && (components != null))
    {
        components.Dispose();
    }
    base.Dispose(disposing);
}

您描述的技术是以模式显示对话框。更多信息-不起作用,主窗口将隐藏在另一个应用程序的窗口后面。Hmmm,请尝试在不带参数的情况下调用ShowDialog()。