我以这样的方式设计应用程序,即“错误”屏幕是一个控件,我将其显示在任何其他控件之上。
public Alert(Control control,string message, Stages stage)
{
InitializeComponent();
control.Controls.Add(this);
Size = new Size(579, 524);
}
public static void Show(Control control,string message, Stages stage)
{
new Alert(control, message, stage).Show();
}
但是,当显示错误屏幕时,代码将继续执行,我不希望这样。我不想使用窗体而不是控件来使用.ShowDialog()功能。错误屏幕上有一个按钮,单击该按钮可恢复代码。
有什么想法吗?
您正在做的不是很标准,因此没有快速简便的方法。您几乎只需禁用其他所有功能。
public static void Show(Control control,string message, Stages stage)
{
new Alert(control, message, stage).Show();
var otherControls = control.Parent.Controls.OfType<Control>().Where( x => x != control).ToList();
foreach (var c in otherControls)
{
c.Enabled = false;
}
}
然后,您当然必须在以后重新启用它们,当然要注意不要重新启用未启用的控件。