C# 激活的表单正在关闭程序
当我从任务栏或通过Alt+Tab激活两个表单时,我正在尝试将它们放在最前面。问题是,如果存在第二个主窗体,我无法关闭主窗体: 这是我使用的代码C# 激活的表单正在关闭程序,c#,C#,当我从任务栏或通过Alt+Tab激活两个表单时,我正在尝试将它们放在最前面。问题是,如果存在第二个主窗体,我无法关闭主窗体: 这是我使用的代码 private void Haupt_Activated(object sender, EventArgs e) { cardLibrary.Focus(); //Focus the second form this.Focus(); //refocus the first one } 我在做什么
private void Haupt_Activated(object sender, EventArgs e)
{
cardLibrary.Focus(); //Focus the second form
this.Focus(); //refocus the first one
}
我在做什么
编辑:
Haupt是主要形式。
CardLib在Haupt中是可变的
CardLib的名称如下:
private void cMenuOpenLibrary_Click(object sender, EventArgs e)
{
if (!Config.libOpen)
{
if (cardLibrary == null) cardLibrary = new CardLib(this);
cardLibrary.Show();
cardLibrary.Left = this.Left - cardLibrary.Width - 5;
cardLibrary.Top = this.Top;
}
}
编辑2:我是在装傻。添加通过Haupt_FormClosed关闭CardLib修复了它。如果您是从
Second.ShowDialog();
然后,当对话框保持焦点直到关闭时,会产生此问题
而不是
Second.ShowDialog();
使用
第二种形式的聚焦如何聚焦第一种形式
this.Focus(); //refocus the first one
也许最好显示一些打开第二个表单的代码?您正在使用
ShowDialog()
?这将解释为什么不能关闭“主窗体”。为什么用户不能先关闭子窗体,然后关闭主窗体?请改用cardLibrary.Show(此)。
this.Focus(); //refocus the first one