C# – how to force user to respond to message box in c# windows application

c

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…

Best Answer

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);
        }