我怎样才能使一个单一实例的形式(而不是应用程序)? [英] How can I make a single instance form (not application)?

查看:116
本文介绍了我怎样才能使一个单一实例的形式(而不是应用程序)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C#应用​​程序,我有一个可以从菜单命令打开选项对话框。

In my C# application I have an option dialog that can be opened from a menu command.

欲确保选项对话框只有一个实例,而不使它模式(用户无法打开在给定时间多于一个选项窗口)。

I want to ensure that the option dialog have only one instance (user cannot open more than one option window at a given time) without making it modal.

此外,如果用户已经有了这个窗口打开了,他点击菜单项再次打开它,应用程序只是使已经可见的形式成为最上面的窗口。

Also if the user already have this window opened, and he clicks in the menu item to open it again, the app just makes the already visible form became the top most window.

任何人都可以点我就如何完成这些任务?路线

Can anyone point me directions on how accomplish these tasks?

非常感谢你。

推荐答案

您将需要这种形式的财产

You will need this form as property

Form1 myForm = null;
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
    myForm = null;
}

private void ShowForm()
{
    if (myForm != null)
    {
        myForm.BringToFront();
    }
    else
    {
        myForm = new Form1;
        myForm.Show();
    }
}

这篇关于我怎样才能使一个单一实例的形式(而不是应用程序)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆