如何在C#中创建“系统modal dialog”?

如何使我的表单成为Windows XP中的“系统模式对话框”

“关闭对话框”,因此除了我在C#中的表单外,不能在Windows中进行任何操作。

我同意Bernarnd的观点,即以这种方式接管系统是“粗鲁的”。

如果你需要这种东西,你可以创建一个类似的效果,如下所示。 这类似于用户帐户控制(“您是否允许以下​​程序对计算机进行更改”)在Vista中引入的模式窗口,它在模式窗口后面显示透明背景。

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // show a "wrapper" form that covers the whole active screen // This wrapper shows the actual modal form Form f = new Form(); f.WindowState = FormWindowState.Maximized; f.FormBorderStyle = FormBorderStyle.None; f.Opacity = 0.5; f.Load += new EventHandler(f_Load); f.Show(); } void f_Load(object sender, EventArgs e) { MessageBox.Show("This is a modal window"); ((Form)sender).Close(); } } 

这是一个不那么粗鲁的方法,因为用户可以ALT-TAB退出模态窗口等。

根据微软的Raymond Chen的说法:

Win32不再具有系统模式对话框。 所有对话框都是其所有者的模态。

此外,您的问题与此问题重复。

这可以通过最大化表格和将不透明度设置为50%来完成

并将表单始终设置为顶部属性为TRUE

并使用KeyHOOK禁用键盘的Win键和Alt键…….

你可以用这个:

 string message = "Hello there! this is a msgbox in system modal"; MessageBox.Show(message is string ? message.ToString() : "Empty Message.", "Message from server", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)4096);