tags:

views:

1431

answers:

5

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...

+1  A: 

If standard implementation of MessageBox doesn't do what you need, you will have to create your own form and use ShowDialog() method.

lubos hasko
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.
Anuya
i am using some other third party applications, which over rides my message box. I want to overcome this.
Anuya
+2  A: 

Take a look at this article

MessageBox.Show Examples in Windows Forms C#

Edit:

You can also use the topmost property of a form to make it on top of all windows in a given application.

How to: Keep a Windows Form on Top

To display a form as a modal dialog call the ShowDialog method.

Form frmAbout = new Form();
frmAbout.ShowDialog();
rahul
+2  A: 

You will have to create your own form, make it modal, change the z-order to make it always on top, and capture all keystrokes and mouse clicks.

Always on top: http://www.codeguru.com/cpp/w-d/dislog/article.php/c1857

Tangurena
+1  A: 

I think you are looking for a System Modal dialog.

Previous thread:

http://stackoverflow.com/questions/1037898/how-to-display-message-box-in-c-as-system-modal

A: 

It sounds like the messagebox is being displayed on another thread. You need to make sure that you call MessageBox.Show on the main UI thread. Below is a code snippet that illustrates a way to achieve this:

public class FooForm: Form
{

   //This is just a button click handler that calls ShowMessage from another thread.
   private void ButtonShowMessage_Click(object sender,EventArgs e)
   {
     //Use this to see that you can't interact with FooForm before closing the messagebox.
     ThreadPool.QueueUserWorkItem(delegate{ ShowMessage("Hello World!");});

     //Use this (uncomment) to see that you can interact with FooForm even though there is a messagebox.
     //ThreadPool.QueueUserWorkItem(delegate{ MessageBox.Show("Hello World!");});
   }

   private void ShowMessage(string message)
   {
     if( InvokeRequire)
     {
       BeginInvoke(new MethodInvoker( () => MessageBox.Show(message))); 
     }
     else
     {
       MessageBox.Show(message);
     }
   }    
}

I am assuming that you don't have a scenario where you have multiple UI threads and when one of them pops a messagebox, you want that messagebox to be modal for the entire UI. That's a more complicated scenario.

Mehmet Aras