开发者

How to make a "system modal dialog" in C#?

开发者 https://www.devze.com 2023-01-21 04:44 出处:网络
How do I make my form a \"system modal dialog\" as in Windows XP? \"Turn off dialog\" so no operation can be made in Windows 开发者_开发知识库except in my form in C#.According to Raymond Chen from Mi

How do I make my form a "system modal dialog" as in Windows XP?

"Turn off dialog" so no operation can be made in Windows 开发者_开发知识库except in my form in C#.


According to Raymond Chen from Microsoft:

Win32 doesn't have system modal dialogs any more. All dialogs are modal to their owner.

Also, your question is a duplicate of this one.


I agree with Bernarnd that taking over the system in this way is "rude".

If you need this kind of thing though, you can create a similar effect as shown below . This is similar to the User Account Control ("Do you want to allow the following program to make changes to the computer") modal window introduced in Vista in that it shows a transparent background behind the modal window.

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

This is a much less rude approach as the user can ALT-TAB out of the modal window etc.


This can be done by maximizing form having and Setting opacity to 50%

and setting Form Always on Top property TRUE

and Disabling the Win key and Alt keys of keyboard using KeyHOOK.......


You could use this:

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

精彩评论

暂无评论...
验证码 换一张
取 消