我有一个启动formB的表单。我希望形成隐藏,直到formb关闭。可能有一个变化formb由formC和其他人打开,所以我只是不能创建一个新的表单。有没有办法启动formB,隐藏和阻止直到关闭?
答案 0 :(得分:9)
这应该这样做。
this.Visible = false;
using (formB as new FormB())
formB.ShowDialog(this);
this.Visible = true;
答案 1 :(得分:0)
您可以使用OnActivate
事件隐藏所有者和Dispose
事件以显示所有者。即使不从另一种形式调用form_b,此解决方案仍然有效:
form_x中的代码:
FormB f = new FormB();
f.Show(this);
form_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);
}