问题描述
亲爱的朋友们,
我正在学习C#windows应用程序。我正在研究MDI表单,并面临如何在MDI表单中保留子表单子表单的问题。让我来描述一下这个问题...
1.我有一个名为'First Form'的MDI表格。
2. MDI表格包含名为'Open Second Form'的菜单栏。
3.在'Open Second Form'上打开一个名为'Second Form'的子表单。
4.the'Second表格'保留在MDI表格中,因为它被编程为MDI的子项。
5.现在,'Second Form'包含一个命令按钮'Open Third Form'。
6.单击按钮打开一个名为Third Form的新表单。
当我拖动它并保持在外面时,第三种形式不会保留在MDI表单中MDI。所以,有没有解决这个问题的方法?
或者如何冻结第三张表格?
谢谢,
Mayank
我是什么尝试过:
我不明白这个问题,我已经看到几乎所有MDI和Child表格的属性但找不到任何解决方案。
Dear Friends,
I am learning C# windows application. I am working on an MDI form and facing a problem that how to keep a sub-form of a child form within the MDI form. Let me describe the problem...
1.I have an MDI form named 'First Form'.
2.The MDI form contains menubar named 'Open Second Form'.
3.Clinking on the 'Open Second Form' opens a child form named 'Second Form'.
4.the 'Second Form' remains within the MDI form as it is programmed as child of MDI.
5.Now, the 'Second Form' contains a command button 'Open Third Form'.
6.Clicking on the button opens a new form named 'Third Form'.
this third form does not remain within the MDI form when I drag it and keep outside of MDI. so, is there any solution of this problem?
or how can I freeze the third form?
Thank You,
Mayank
What I have tried:
I don't understand this problem, i have seen almost all properties for MDI and Child forms but couldn't find any solution.
推荐答案
public Action NotifyMainFormToOpenChildForm2;
private void btnNotify_Click(object sender, EventArgs e)
{
if (NotifyMainFormToOpenChildForm2 != null)
{
NotifyMainFormToOpenChildForm2();
}
}
3.b。在MDI父表单中:
3.b. in the MDI Parent Form:
private ChildForm1 cForm1;
private ChildForm2 cForm2;
private void MDIParentForm_Load(object sender, EventArgs e)
{
cForm1 = new ChildForm1();
cForm1.MdiParent = this;
cForm1.NotifyMainFormToOpenChildForm2 += NotifyMainFormToOpenForm2;
cForm2 = new ChildForm2();
cForm2.MdiParent = this;
cForm1.Show();
}
private void NotifyMainFormToOpenForm2()
{
cForm2.Show();
}
在这个例子中,我们注入一个指向可执行代码的指针,该代码将ChildForm2(在MDIParentForm中)打开到ChildForm1中。我们使用委托来执行此操作,Type Action的委托给我们一个易于使用的语法。
当在ChildForm1中单击Button时,它会检查以查看如果对Action委托中的代码有一个有效的引用,并且,如果存在,它将执行位于MDIParentForm上的处理程序中的代码,并且该代码显示ChildForm2。
重新设置能够拖动MDI子窗体的问题,使它们部分超出MDI父窗体的边界:嗯,这是MDI模型的缺陷之一,即imho。要使其正常工作,需要使用Windows API来抑制显示ScrollBars,因为控件中存在内部缺陷。
我今天已经用完了(GMT + 7),但是如果你发布另一个关于将子表格限制在MDI父表格边界的问题......你已经尝试自己解决这个问题,我会回复。
In this example we inject a pointer to the executable code that opens ChildForm2 (in the MDIParentForm) into ChildForm1. We used a delegate to do this, a delegate of Type Action which gives us an easy to use syntax.
When the Button is clicked in ChildForm1, it checks to see if there is a valid reference to code in the Action delegate, and, if there is, it executes that code which is located in the handler on the MDIParentForm, and that code show ChildForm2.
Re the problem of being able to drag MDI Child Forms so they are partially outside the boundaries of the MDI Parent Form: well, that's one of the flaws of the MDI model, imho. Getting that to work right requires using the Windows API to suppress showing ScrollBars because of an internal flaw in the Control.
I have run out of time for today (GMT +7), but if you post another question about the issue of constraining Child Forms to the boundaries of an MDI Parent Form ... and you have made some attempt to solve that problem for yourself, I will respond.
这篇关于如何在MDI父表单中设置子表单的子表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!