Create a Modeless Messagebox

Smashery picture Smashery · Jun 17, 2010 · Viewed 29.1k times · Source

How might one go about creating a Modeless MessageBox? Do I have to just create my own Windows Form class and use that? If so, is there an easy way of adding a warning icon (rather than inserting my own image of one) and resizing based on text volume?

Answer

tojotamies picture tojotamies · May 17, 2011

If you need a message box that just displays itself while your code continues running in the background (the box is still modal and will prevent the user from using other windows until OK is clicked), you can always start the message box in its own thread and continue doing what ever you do in the original thread:

    // Do stuff before.
    // Start the message box -thread:
    new Thread(new ThreadStart(delegate
    {
      MessageBox.Show
      (
        "Hey user, stuff runs in the background!", 
        "Message",
        MessageBoxButtons.OK,
        MessageBoxIcon.Warning
      );
    })).Start();
    // Continue doing stuff while the message box is visible to the user.
    // The message box thread will end itself when the user clicks OK.