0

I have created single instance windows application, when i minimize the window app goes to system tray. Now i want to restore it from system tray without making double click on notifyicon ( i can use Run Window , Or desktop shortcut)

Below is my code

        [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;
                        }
                    }
                }
            }
        }
Nitin Patil
  • 110
  • 10
  • just add a `MouseClick` event to your `notifyicon` and show application on this event – WhileTrueSleep May 12 '17 at 12:47
  • This is a built-in feature in the .NET framework. The default action of the [StartupNextInstance event](https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.applicationservices.windowsformsapplicationbase.startupnextinstance(v=vs.110).aspx) is to make the first window visible again, so you probably don't even have to write the event handler. – Hans Passant May 12 '17 at 13:37

0 Answers0