Search code examples
c#.netwinformsmessageboxsystem-tray

C# MessageBox To Front When App is Minimized To Tray


I have some code that popups a message box:

MessageBox.Show(this,
                 "You have not inputted a username or password. Would you like to configure your settings now?",
                 "Settings Needed",
                 MessageBoxButtons.YesNo,
                 MessageBoxIcon.Question);

My problem is when this pops up my app is usually minimized to the tray. As a result the messagebox doesn't come to the front and it also doesnt appear along the start bar. The only way of seeing it is by alt-tabbing.

Here is the code that minimizes my app (the parent) to the tray:

if (FormWindowState.Minimized == WindowState)
{                
      Hide();                
}

Solution

  • you can try like this

    MessageBox.Show(new Form() { TopMost = true }, "You have not inputted a username or password. Would you like to configure your settings now?",
                     "Settings Needed",
                     MessageBoxButtons.YesNo,
                     MessageBoxIcon.Question);