我认为你可以假模态窗口,因此它不是模式,但禁用调用者。我在一个自己的项目中使用了这个。我这样做:
//Setup small Interface
public interface IDialog
{
//Our own Event which tell the caller if the Dialog is active/inactive
public event DialogChangedEventArgs DialogChanged;
}
//Setup EventArgs for our own Event
public class DialogChangedEventArgs : EventArgs
{
public bool DialogActive{get;}
public DialogChangedEventArgs(bool dialogActive)
{
DialogActive = dialogActive;
}
}
//Setup the Form which act as Dialog in any other form
public class Form2 : Form, IDialog
{
public event EventHandler<DialogChangedEventArgs> DialogChanged;
//If this Form is shown we fire the Event and tell subscriber we are active
private void Form2_Shown(object sender, EventArgs e)
{
DialogChanged?.Invoke(this, true);
}
//If the user close the Form we telling subscriber we go inactive
private void Form2_Closing(object sender, CancelEventArgs e)
{
DialogChanged?.Invoke(this, false);
}
}
public class Form1 : Form
{
//Setup our Form2 and show it (not modal here!!!)
private void Initialize()
{
Form2 newForm = new Form2();
newForm.DialogChanged += DialogChanged;
newForm.Show();
}
private void Form2_DialogChanged(object sender, DialogChangedEventArgs e)
{
//Now check if Form2 is active or inactive and enable/disable Form1
//So just Form1 will be disabled.
Enable = !e.DialogActive;
}
}
这很简单。只需使用一个事件来告诉你的第一个表格:Hey iam第二个表格并激活。然后,您可以在第二个活动时禁用第一个窗体。您可以完全控制哪些表单处于活动状态。希望这可以帮助。
模式对话框仅禁用它的所有者。目前还不清楚你已经实现了什么设置,所以模态对话框也会禁用这些额外的窗口。 – IInspectable
增加了一个示例来说明您所说的看起来不是这种情况。 – user109078