c# - 在 C# 中仅打开一次 Windows 窗体

标签 c# winforms

<分区>

Possible Duplicate:
How to avoid multiple instances of windows form in c#

我想在应用程序中只显示一次打开的窗体,而不是将它们创建为 MDI 窗体。

最佳答案

在从您的代码打开表单之前,检查 Application.OpenForms属性并查看表单是否存在于集合中。

类似于:

if ((Application.OpenForms["Form1"] as Form1) != null)
{
 //Form is already open
}
else
{
// Form is not open
}

关于c# - 在 C# 中仅打开一次 Windows 窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14351925/

相关文章:

c# - 如何在 Internet Explorer 中显示来自 BHO 的警告或栏?

c# - 在发布配置中随机崩溃

c# - 在 C# 中使用通用存储库时连接多个表

c# - 如何禁用 DataGridView 中的排序?

c# - 从未设置 WinRT DependencyProperty

c# - 查询 IEnumerable 中具有相似属性且在特定时间阈值内的对象

c# - DataGridView 在显示之前不会自动调整列大小

c# - TableLayoutPanel GetCellPosition 和 GetPositionFromControl,它们有何不同?

c# - 在更改之前获取值

c# - Windows 窗体中的异步