Javed Akram
Javed Akram

Reputation: 15344

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

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

Upvotes: 2

Views: 10154

Answers (4)

QCodeX
QCodeX

Reputation: 11

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

Upvotes: 1

Javed Akram
Javed Akram

Reputation: 15344

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

Upvotes: 1

steinar
steinar

Reputation: 9653

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.

Upvotes: 5

Bernard
Bernard

Reputation: 7961

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.

Upvotes: 6

Related Questions