0

I want to show messagebox to the user, such that the user cannot refuse to confirm the message box. User should not be allowed to do anything else in the screen until he confirms the messagebox. This is a windows based c# application. The main thing is, even if i use windows message box. Some times it is hiding behind some screen. But for my case, i want message box to be on top most whenever it appears. I am using some other third party applications, which over rides my message box. I want to overcome this. How to do this...

Anuya
  • 8,082
  • 49
  • 137
  • 222
  • First bring your application to the front, and then show the MessageBox() ?? – Mitch Wheat Sep 10 '09 at 02:47
  • Show your code to show **MessageBox**. – KV Prajapati Sep 10 '09 at 02:48
  • This is a repeat of the same question by the same user http://stackoverflow.com/questions/1391952/messagebox-in-c. @karthik please don't repeat the same question. If the answers you got are not helping you, you need to provide more information to help others help you. – Mehmet Aras Sep 10 '09 at 02:54

4 Answers4

1

You might have to define a custom message box (a Form) and set its TopMost property to true.This will make it on top of ever other window, except other TopMost windows.

That's assuming you want it on top of other applications too, which I'm not sure it's what you're looking for...

Bryan Menard
  • 13,234
  • 4
  • 31
  • 47
1

Invoke messagebox inside the constructor of your form.

  public Form1()
        {
            if (MessageBox.Show(this, "Confirm?", "Attention", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
            }
            else
            {
            }
            InitializeComponent();
        }

OR

Invoke another form instance using ShowDialog() method,

  public Form1()
        {
           Form2 frm=new Form2();
           frm.ShowDialog(this);
        }
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

The normal windows MessageBox() function should do exactly this unless I'm missing something in your question.

Adam Pierce
  • 33,531
  • 22
  • 69
  • 89
0

Always specify a owner when displaying a message box.

Pierre-Alain Vigeant
  • 22,635
  • 8
  • 65
  • 101