c# winforms - 如何在不使父窗体不可见的情况下将子窗体置于父窗体前面? [英] c# winforms - How can I get the child form in front of parent form without making the parent one invisible?

查看:23
本文介绍了c# winforms - 如何在不使父窗体不可见的情况下将子窗体置于父窗体前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题不是

我读过使用 childform.ShowDialog() 但我不想要那样,因为这会使父窗体在显示子窗体时不可见.我希望两者都可见.

我听说过BringToFront 不起作用,因为它用于控件而不是表单,并且用于使用Activate,但是正如您所看到的,我已经尝试过Activate,但它也不起作用.

解决方案

在表单的 Shown 事件中尝试您的代码.这样,第二个窗体显示在主窗体之后,因此应该会变为活动状态.

This question is not a duplicate of Win Form in front of parent form

because the author of that one didn't seem to mind if the parent form was hidden, and the answers suggesting ShowDialog() hide the parent. I don't want the parent form hidden.

I have the following code in form_load

    private void Form1_Load(object sender, EventArgs e)
    {
        var childform = new Form();           
        childform.Show();
        childform.BringToFront();           
        childform.Activate();
    }

Yet it won't show the child in front of the parent. It shows this, as you can see, it's showing the parent form in front and the child behind, rather than the other way around which I want.

I've read of using childform.ShowDialog() but I don't want that because that would make the parent invisible while the child form shows. I want both visible.

I've read that BringToFront won't work 'cos it's for controls not forms, and to use Activate, but as you can see i've tried Activate and it isn't working either.

解决方案

Try your code in the form's Shown event. That way the second form is shown after the main form and should thus become active.

这篇关于c# winforms - 如何在不使父窗体不可见的情况下将子窗体置于父窗体前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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