如何在MDI父表单中打开MDI子表单。 [英] How to open a MDI child form in MDI parent form.

查看:77
本文介绍了如何在MDI父表单中打开MDI子表单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MDI form0中有一个Form1。当一个单元格的验证在form1中显示错误时,我在同一个MDI父窗体0中打开一个新的form2。我已为该单元格验证设置了自定义条件并设置了错误消息。下面是在MDI Parent中显示
表单的代码部分,

I have a Form1 in MDI form0. I'm opening a new form2 in in the same MDI parent form0 when validation of a cell shows error in the form1. I have set my custom condition for that cell validation and set an error message. below are the code part to show the forms in MDI Parent,

//To open the Form1 in MDI form0
Form1 ChildForm = new Form1();
ChildForm.MdiParent = this;
ChildForm.Show();

//To open a form when validation shows error


if(((string)dataGridView1.Rows [e.RowIndex] .Cells [e.ColumnIndex] .Value).Length> 4)

{

    Form2 ChildForm = new Form2(this);

    ChildForm.MdiParent = this.MdiParent;

    ChildForm.Show();

    this.dataGridView1.Rows [e.RowIndex] .Cells [e.ColumnIndex] .ErrorText =" Error"; $
    e.Cancel = true;

}

 

我面临的问题是,只要我点击单元格外,就会打开form2。

if (((string)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value).Length > 4)
{
    Form2 ChildForm = new Form2(this);
    ChildForm.MdiParent = this.MdiParent;
    ChildForm.Show();
    this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Error";
    e.Cancel = true;
}
 

The problem I'm facing is, the form2 is opened when whenever I click on outside of the cell.

有什么建议可以解决这个问题吗?为什么form2被打开太多次了?

Any suggestions to resolve this issue? why the form2 is opened too many times?

请参考https://drive.google.com/open?id = 0Bwk9nUFE3rlxNkxWSFB6NzByZEE 

Please refer to the https://drive.google.com/open?id=0Bwk9nUFE3rlxNkxWSFB6NzByZEE 

问候,

Arulpriya

Arulpriya

推荐答案

嗨Arulpriya,

Hi Arulpriya,

我已经在我的VS2017中测试了它发现我无法重现您的问题,按钮点击事件可以在在MDI父表单中的form2,实际上,form1和form2都是MDI子表单,如果可以触发form1的事件
(如你所说,form2显示单元格的验证在表单1中显示错误),然后form2的事件也可以在正常情况下触发,除非你做其他事情来限制它。

I have tested it in my VS2017 find that I can not reproduce your problem, the button click event can be triggered in the form2 within the MDI parent form, actually, the form1 and form2 are both the MDI child forms, if the form1's event can be triggered(as you said, form2 shows when validation of a cell shows error in the form1), then form2's event can also be triggered under normal circumstances unless you do something else to limit it.

我建议你提供简单的演示,可以重现这个问题然后上传到Microsoft OneDrive如果可能的话,我可以测试它并尝试找到一些解决方案。

I suggest you can provide your simple demo which can reproduce this issue then upload it to Microsoft OneDrive if it is possible so that I can test it and try to find some solutions.

最好的问候,

Stanly


这篇关于如何在MDI父表单中打开MDI子表单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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