如何从多个打开的前面带子窗体? [英] How to bring front child form from multipled opened from?

查看:50
本文介绍了如何从多个打开的前面带子窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我今天是satardekar,

在我的csharp winform MDI应用程序中,有5个子窗体.

单击后,我只希望每个子表单有一种表单.

哪个适合我.我已经使用静态计数器实现了这一点.


当用户打开每个子窗体后单击下一步"时,我想在前面单击实例.


我的代码是这样的:

Hi, I am uday satardekar,

In my MDI application in csharp winform there is 5 child form.

And I want only one form of each child form after click.

Which work properly for me. I have achieved this using static counter .


When user click next after opening each child form, I want clicked instance in front.


My code is like this:

private void retriveDataToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            int instances = RetriveDataForm.instanceCount;
            if (instances < 1)
            {
                RetriveDataForm retrieveDataForm = new RetriveDataForm();
                retrieveDataForm.MdiParent = this;
                retrieveDataForm.Show();
            }

        }

        private void manualEntryToolStripMenuItem1_Click(object sender, EventArgs e)
        {
             int instances = ManualEntryForm.instanceCount;
             if (instances < 1)
             {
                 ManualEntryForm manualEntry = new ManualEntryForm();
                 manualEntry.MdiParent = this;
                 manualEntry.Show();
             }
        }


假设 retrieveDataForm manualEntry 已经打开,并且当用户下次在 manualEntry 表单上单击时,我希望它位于所有打开的表单的前面. >
我在其他无法正常使用的块中使用了manualEntry.BringToFront(); .
请给我解决方案.


Suppose retrieveDataForm and manualEntry are already opened and when user click next time on manualEntry form, I want it front of all opened form.

I have use manualEntry.BringToFront(); in else block which is not working.
Please give me solution.

推荐答案

关于此,
use manualEntry.Activate();

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activate.aspx[^]




我有这样的用途




i have use like this

int instances = StatusForm.instanceCount;
          int instances = ManualEntryForm.instanceCount;
             if (instances < 1)
             {
                 ManualEntryForm manualEntry = new ManualEntryForm();
                 manualEntry.MdiParent = this;
                 manualEntry.Show();
             }
           else
           {

               manualEntry .Activate();
             
           }




但它不能正常工作
请给我解决方法


谢谢




but it is not working properly
please give me solution


thanks


您无需计数.只需枚举现有打开的表单,然后找到 manualEntry ,则调用它的Activate方法.否则,请创建它.

You don''t need to count anything. Just enumerate the existing opened forms, and if you find manualEntry, call it''s Activate method. Otherwise, create it.

foreach (Form child in mainForm.Children)
{
    if (child is manuEntry)
    {
        child.Activate();
        break;
    }
}
if (!(this.ActiveMdiChild is manualEntry))
{
    manualEntry form = new manuEntry();
    form.Show();
    form.Focus();
}


我认为John的意思是mainForm.MdiChildren
I think John meant mainForm.MdiChildren


这篇关于如何从多个打开的前面带子窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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