[英]Opening a child form from another child form and set MDI to parent form - how to do?
I have a MDI form.我有一个 MDI 表格。 within this MDI form I can open some child forms using:
在这个 MDI 表单中,我可以使用以下方法打开一些子表单:
This is within MainForm
这是在
MainForm
Form1 f1 = new Form1;
f1.MdiParent = this; //this refers to MainForm (parent)
f1.Show();
This works as expected!这按预期工作!
But Now, while I am in the child form (Form1 -> f1) I want to open another form as a child for MainForm
but when I use this
keyword it will reffer to f1
.但是现在,当我处于子窗体 (Form1 -> f1) 时,我想打开另一个窗体作为
MainForm
的子窗体,但是当我使用this
关键字时,它会指向f1
。 How can I open the new form within f1
and set its MdiParent
to MainForm
?如何在
f1
打开新表单并将其MdiParent
设置为MainForm
?
Try assigning the parent form of your first child from:尝试从以下位置分配您的第一个孩子的父表单:
Form2 f2 = new Form2;
f2.MdiParent = this.ParentForm; //this refers to f1's parent, the MainForm
f2.Show();
Hope this helps.希望这可以帮助。
Let us suppose that the second form is f2.Then, the code in form f1 to create a new form f2 in MDI parent form will be:让我们假设第二个窗体是 f2。那么,窗体 f1 中在 MDI 父窗体中创建新窗体 f2 的代码将是:
Form2 f2 = new Form2;
f2.MdiParent = this.MdiParent;
f2.Show();
Well, not to argue with the "solution" that was listed... but if I'm understanding the request correctly and trying the above solution didnt work i would do the following....好吧,不要与列出的“解决方案”争论……但是如果我正确理解了请求并且尝试上述解决方案不起作用,我会执行以下操作……
Form2 f2 = new Form2();
f2.MdiParent = MDIParent1.ActiveForm;
f2.Show();
Let us suppose that the second form is frm2.Then, the code in form frm1 to create a new form frm2 in MDI parent form will be: create new object then again retrived data mdiparent forms solved freeze dispose form让我们假设第二个表单是 frm2。那么,在表单 frm1 中在 MDI 父表单中创建新表单 frm2 的代码将是:创建新对象然后再次检索数据 mdiparent 表单解决了冻结处置表单
Dim dru as New frm2 '// another form call
dru = New frm2
dru.mdiparent = frm1 '// main forms
dru.show()
I had the same problem and tried all different solutions.我遇到了同样的问题并尝试了所有不同的解决方案。 Finally the one that worked for me was:
最后,对我有用的是:
Dim ChildForm As New AddingText("")
' Make it a child of this MDI form before showing it.
ChildForm.MdiParent = MDIParent1
ChildForm.Dock = DockStyle.Fill
MDIParent1.m_ChildFormNumber += 1
ChildForm.Text = "Client Existent" & MDIParent1.m_ChildFormNumber
ChildForm.Show()
the hiccup is that could not be used in conjunction with ShowDialog(), but i can live with it.打嗝是不能与 ShowDialog() 结合使用,但我可以忍受它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.