MessageBox in C #

I want to show the message to the user, so that the user cannot refuse to acknowledge the message. The user is not allowed to do anything else on the screen until he confirms the message.

This is a Windows based C # application.

The main thing, even if I use the Windows message box. Several times he hides behind some screen. But for my case, I want the message box to be on top when it appears.

I use some other third-party applications that carry my message box. I want to overcome this.

How to do it...

+5
source share
5 answers

MessageBox.Show Windows Forms #

Edit:

, .

Windows

, ShowDialog.

Form frmAbout = new Form();
frmAbout.ShowDialog();
+4

MessageBox , , ShowDialog().

+2

, System Modal.

:

# ?

+1

, . , MessageBox.Show . , :

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

, , , , , . .

+1

All Articles