如何在MDI父表单中设置子表单的子表单? [英] How to set sub-form of a child form within MDI parent form?

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

问题描述

亲爱的朋友们,



我正在学习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.

推荐答案

我会说:使用MDI这是一个非常糟糕的主意。请检查: WindowsApplication with MDI [ ^ ]
I'd say: this is a really bad idea to use MDI. Check this: WindowsApplication with MDI[^]


如果可能的话,我建议你不要使用MDI适用于您的应用程序的WinForm架构;它已经过时了;它在视觉上没有吸引力;并且,有更好的方法来构建包含元素的UI(使用UserControls或Panels,或使用TabControl)。



WinForm永远不会两者 MDIParent表格和MDIChild表格;我希望你在这里没有考虑到这一点。虽然你确实可以把一张表格包含在另一张表格(不是MDIParent表格)中,但我强烈建议你永远不要这样做。



建议:



1.在您的主表单(MDIParent)中,创建您需要显示为MDIChild表单的所有表单的实例。



2.在需要时显示这些子表单。



3.如果您希望子表单中的事件导致MDI UI发生某些变化,比如打开另一个儿童表格:



3.a.在ChildForm1中:
If at all possible, I suggest you do not use the MDI WinForm architecture for your application; it's outmoded; it's visually unappealing; and, there are better ways to construct a UI that has contained elements (use UserControls, or Panels, or use a TabControl).

A WinForm can never be both an MDIParent Form and an MDIChild Form; I hope you didn't have that in mind, here. While you can, indeed, make a Form contained within another Form (not an MDIParent Form), I strongly suggest you never do that.

Suggestions:

1. in your Main Form (the MDIParent), create instances of all the Forms you will need to show as MDIChild Forms.

2. show these Child Forms when you need to.

3. if you want an event in a Child Form to cause some change in the MDI UI, like opening another Child Form:

3.a. in ChildForm1:
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父表单中设置子表单的子表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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