要设置Winform窗体只能打开一个实例,可以使用单例模式来实现。
private static Form1 instance;
private Form1()
{
InitializeComponent();
}
public static Form1 GetInstance()
{
if (instance == null || instance.IsDisposed)
{
instance = new Form1();
}
return instance;
}
Form1 form = Form1.GetInstance();
form.Show();
这样,无论调用多少次GetInstance方法,都只会返回同一个窗体实例,确保了只能打开一个窗体。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux如何打开一个程序