Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从系统托盘恢复MDI窗体窗口,无需单击Notify图标c#_C#_.net_Winforms_Notifyicon - Fatal编程技术网

从系统托盘恢复MDI窗体窗口,无需单击Notify图标c#

从系统托盘恢复MDI窗体窗口,无需单击Notify图标c#,c#,.net,winforms,notifyicon,C#,.net,Winforms,Notifyicon,我已经创建了单实例windows应用程序,当我最小化窗口时,应用程序将进入系统托盘。现在我想从系统托盘中恢复它,而不必双击notifyicon(我可以使用运行窗口或桌面快捷方式) 下面是我的代码 [STAThread] static void Main() { bool createdNew = true; using (Mutex mutex = new Mutex(true, "frm_takes

我已经创建了单实例windows应用程序,当我最小化窗口时,应用程序将进入系统托盘。现在我想从系统托盘中恢复它,而不必双击notifyicon(我可以使用运行窗口或桌面快捷方式)

下面是我的代码

        [STAThread]
        static void Main()
        {
            bool createdNew = true;
            using (Mutex mutex = new Mutex(true, "frm_takescreens", out createdNew))
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);


                    const string REGISTRY_KEY = @"HKEY_CURRENT_USER\Toposcreen";
                    const string REGISTY_VALUE = "FirstRun";
                    if (Convert.ToInt32(Microsoft.Win32.Registry.GetValue(REGISTRY_KEY, REGISTY_VALUE, 0)) == 0)
                    {
                        Microsoft.Win32.Registry.SetValue(REGISTRY_KEY, REGISTY_VALUE, 1, Microsoft.Win32.RegistryValueKind.DWord);
                        Application.Run(new frm_dir());
                    }
                    else
                    {
                        Application.Run(new frm_mdi());
                    }
                }
                else
                {
                    Process current = Process.GetCurrentProcess();
                    foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                    {
                        if (process.Id != current.Id)
                        {
                            SetForegroundWindow(process.MainWindowHandle);
                            break;
                        }
                    }
                }
            }
        }

只需将
MouseClick
事件添加到您的
notifyicon
并在此事件上显示应用程序这是.NET framework中的内置功能。的默认操作是使第一个窗口再次可见,因此您甚至不必编写事件处理程序。