2

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Javed Akram
  • 15,024
  • 26
  • 81
  • 118

4 Answers4

6

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.

Community
  • 1
  • 1
Bernard
  • 7,908
  • 2
  • 36
  • 33
5

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.

steinar
  • 9,383
  • 1
  • 23
  • 37
1

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

Javed Akram
  • 15,024
  • 26
  • 81
  • 118
1

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);
Pang
  • 9,564
  • 146
  • 81
  • 122
  • 40956 is no longer supported for MessageBoxOptions. Supported values are: DefaultDesktopOnly = 131072 The message box is displayed on the active desktop. RightAlign = 524288 The message box text is right-aligned. RtlReading = 1048576 Specifies that the message box text is displayed with right to left reading order. ServiceNotification = 2097152 The message box is displayed on the active desktop. – Randall Deetz Oct 10 '18 at 16:25