Notify Icon show form

  • Thread starter Thread starter John B
  • Start date Start date
J

John B

I have a utility that minimizes to the system tray.
When I double click or right-click and select restore I want to show the
window and for it to be the active window again.
I have tried
this.Show
this.Activate
this.BringToFront

But in all cases, the form just restores to the task bar and does not
show itself.

The only way I could do it was with the win23 api's
ShowWindowAsync and SetForegroundWindow.

This is fine and works as desired, I just wondered if I was missing
anything and there was a managed way to do it?

Cheers
JB
 
John B said:
I have a utility that minimizes to the system tray.
When I double click or right-click and select restore I want to show the
window and for it to be the active window again.
I have tried
this.Show
this.Activate
this.BringToFront

for me this works:
*********************************
private void notifyIcon1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
this.Show();
this.Activate();
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
}

*********************************
additionally:
*********************************
// after Form initialisation
this.Resize += new EventHandler(HideForm);

void HideForm(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.Hide();
}
else this.Show();
}
*********************************

RGDS PSG
 
psg said:
for me this works:
*********************************
private void notifyIcon1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
this.Show();
this.Activate();
if (this.WindowState == FormWindowState.Minimized)
{
this.WindowState = FormWindowState.Normal;
}
}

*********************************
additionally:
*********************************
// after Form initialisation
this.Resize += new EventHandler(HideForm);

void HideForm(object sender, EventArgs e)
{
if(this.WindowState == FormWindowState.Minimized)
{
this.Hide();
}
else this.Show();
}
*********************************

RGDS PSG
Works beautifully.
Thanks
I didnt set the form.windowstate, which is why it never brought it back up.

Cheers
JB
 
Back
Top