Keep Messagebox.show() on top of other application using c#

后端 未结 3 2015
遇见更好的自我
遇见更好的自我 2020-12-08 13:08

How to keep a Messagebox.show() on top of other application using c# ??

相关标签:
3条回答
  • 2020-12-08 13:59

    I tried the solution provided by donutboy and it doesn't seem to accept 0x40000 (or 40000) as a valid option as a MessageBoxOptions Enum value.

    However I have found that using MessageBoxOptions.DefaultDesktopOnly has the same effect and keeps the MessageBox on top until it is confirmed by the user. ie.

    MessageBox.Show("Hello there", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
    

    This is likely the simplest native solution on offer.

    0 讨论(0)
  • 2020-12-08 14:02

    Another easy way to handle this:

    MessageBox.Show(new Form { TopMost = true }, "This is TopMost", "TopMost", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    
    0 讨论(0)
  • 2020-12-08 14:10

    There's a better solution, without creating a new form.

    MessageBox.Show("Message Text", "Header", MessageBoxButtons.OK, MessageBoxIcon.None, 
         MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);  // MB_TOPMOST
    

    The 0x40000 is the "MB_TOPMOST"-Flag.

    0 讨论(0)
提交回复
热议问题