C# / .NET messagebox is not modal
You need to assign the MessageBox owner property to the main UI window (look at the 3rd constructor).
This is a simple C# new Windows-Forms application:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string message = "You did not enter a server name. Cancel this operation?";
string caption = "No Server Name Specified";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(this, message, caption, buttons);
if (result == DialogResult.Yes)
{
// Closes the parent form.
this.Close();
}
}
}
}
As Dusty states in his answer, a message box is a modal dialog. Specify the owner
property. In this example, the owner is denoted by the keyword this
.
To get system modal messagebox set MessageBoxOptions.DefaultDesktopOnly.