如何使一个"系统模态对话框"在C#中? [英] How to make a "system modal dialog" in C#?

查看:233
本文介绍了如何使一个"系统模态对话框"在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让我的形式系统模式对话框在Windows XP?

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

关闭对话框,所以没有操作可以在Windows进行,除了在我的C#的形式。

"Turn off dialog" so no operation can be made in Windows except in my form in C#.

推荐答案

我同意Bernarnd,服用过该系统以这种方式是粗鲁。

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

如果你需要这种东西,虽然,你可以如下图所示创建一个类似的效果。这是类似的用户帐户控制(你要允许以下程序进行更改电脑),因为它显示了模态窗口后面透明背景在Vista中引入的模态窗口。

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

这是一个更粗鲁的方法,因为用户可以 ALT-TAB 出模式窗口等。

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

这篇关于如何使一个"系统模态对话框"在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆