ok, the title is pretty long and should tell the problem i'm facing with.
Here is the code when minimizing to icon tray:
void MainFormResize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
this.ShowInTaskbar = false;
}
}
When the program is already opened and in sys tray, and still someone wants to open another instance of it, then:
private static void Main(string[] args)
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "IPADcommunicator", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
IntPtr handle = FindWindow(null,"IPADcommunicator");
SetForegroundWindow(handle);
ShowWindow(handle,5);
break;
}
}
...
Howeve, it is not working properly. The mainwindow is not restored.
I've googled a lot and haven't found solutions for that problem.
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…