Windows.Forms的,显示非模态禁用的形式 [英] Windows.Forms, showing a disabled form in non-modal state

查看:133
本文介绍了Windows.Forms的,显示非模态禁用的形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦,显示非模态禁用的形式。下面是例子code:

I have some trouble showing a disabled Form in non-modal state. Here is the example code:

public partial class Form1 : Form
{
    // ....
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            Form2 form = new Form2();
            form.Enabled = false;
            form.Show();    // works, but form has no owner
            // form.Show(this); // gives an System.InvalidOperationException
            // ...
            // ... my program here shows a message box, ask user for something
            // ... while 'form' is shown in the background 
            form.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

    }
}

任何想法,为什么显示()(不带参数)的作品,但显示(本)给出了一个例外?在我的情况下,表格必须知道它的主人要正确显示,这样我就可以做到以下几点:

Any idea why Show() (without parameter) works, but Show(this) gives an exception? In my scenario, form must know its owner to be shown correctly, so I can do the following:

            form.Enabled = false;
            form.Owner=this;
            form.Show();

不过,这真的是一个很好的解决方案?

but is this really a good solution?

编辑:感谢您的快速解答。看来我们真的找到这里的框架中的错误。尽管你的建议,我想我会继续用我的解决方案,因为经过显示禁止的形式给出了一个丑陋的明显效果给用户。

Thanks for the quick answers. Seems that we really found a bug in the framework here. In spite of your suggestions, I think I will keep with my solution, since disabling the form after the 'Show' gives an ugly visible effect to the user.

推荐答案

这或致电显示(本),然后禁用它是我能想到的只有两种方式的。

That or call Show(this) and then disable it are the only two ways that I can think of.

这篇关于Windows.Forms的,显示非模态禁用的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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