Problem with BringToFront()

  • Thread starter Thread starter C# Learner
  • Start date Start date
C

C# Learner

BringToFront() has the desired effect in my app if the notify icon's
(system tray icon's) context menu is used. However, I can't
BringToFront() in response to a Click event handler.

Here's the code:

private void showContextMenuItem_Click(object sender,
System.EventArgs e)
{
DoShow(); // BringToFront() in DoShow() will work here.
}

private void notifyIcon_Click(object sender, System.EventArgs e)
{
DoShow(); // BringToFront() in DoShow() DOES NOT work here.
}

private void DoShow()
{
Show();

if (WindowState == FormWindowState.Minimized) {
WindowState = FormWindowState.Normal;
}
BringToFront();
}

Anyone have an idea?
 
<snip>

Fixed it! Here's the new DoShow() method that works:

private void DoShow()
{
if (WindowState == FormWindowState.Minimized) {
WindowState = FormWindowState.Normal;
}
Activate();
}
 
Back
Top