MDI父窗体问题设置父窗体

发布于 2024-10-07 11:37:08 字数 721 浏览 5 评论 0原文

我正在使用一个有子项的 MDI 父窗体,当它们被该父项调用时,它们显示得很好,并且我用来强化子窗体,

ChildForm child = new ChildForm();
child.IsMdiContainer= this;
child.Show();

一旦从父控件调用它们,它们就会很好地工作,但如果我从另一种形式不是任何父窗体的子窗体,那么它们不再是主要父窗体的子窗体,一个明显的原因是,当我在该独立窗体上强化它们时,我根本无法使用 child.MDIParent = this;因为它倾向于使独立的表单父级,但我也尝试过

MDIParentForm form = new MDIParentForm 

ChildForm child = new ChildForm();
child.IsMdiContainer= form ;
child.Show();

,但这也没有帮助,而是抛出一个异常,即我尝试设置父级的表单不是 MDI 容器,然后对此我尝试并修改

MDIParentForm form = new MDIParentForm ;
form.IsMdiContainer= true;
ChildForm child = new ChildForm();
child.MDIParent = form ;
child.Show();

结果什么也没有出现

任何想法如何............

I am using a MDI parent form that has a childs and they show up very well when they are called up by this parent and i use to intensiate child form as

ChildForm child = new ChildForm();
child.IsMdiContainer= this;
child.Show();

works well as soon as they are called from parent control but if i call them from another form that is not child of any parent form then they no longer remains child of main parent one obvious reason is that when i intensiate them on that independent form is that I simply cannot use child.MDIParent = this; because it will tend to make independent form parent but i also have tried

MDIParentForm form = new MDIParentForm 

ChildForm child = new ChildForm();
child.IsMdiContainer= form ;
child.Show();

but this also dose not help instead of this it throws an exception that the form that I am trying to set Parent is not MDI Container then to this I give a try and modify

MDIParentForm form = new MDIParentForm ;
form.IsMdiContainer= true;
ChildForm child = new ChildForm();
child.MDIParent = form ;
child.Show();

and in its result nothing appears

Any idea how to..........

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

时光与爱终年不遇 2024-10-14 11:37:09

您应该将 Parent 设置为已经存在的 mdiform,而不是创建一个新的。

如果还没有 mdiform 的实例,您不仅应该创建该表单的实例,还应该显示它。

var mdiForm = new MdiForm();
mdiForm.IsMdiContainer = true;
var childForm = new ChildForm();
childForm.MdiParent = mdiForm;
mdiForm.Show();
childForm.Show();

另请注意,我使用 mdiForm.IsMdiContainer,据我所知,没有 IsMdiParent 属性。

You should set the Parent to be the already existing mdiform, not create a new one.

If there isn't an instance of the mdiform already, you should not only create an instance of the form, but also show it.

var mdiForm = new MdiForm();
mdiForm.IsMdiContainer = true;
var childForm = new ChildForm();
childForm.MdiParent = mdiForm;
mdiForm.Show();
childForm.Show();

Also notice that I use mdiForm.IsMdiContainer, AFAIK there is no IsMdiParent property.

夏雨凉 2024-10-14 11:37:09

在父表单中编写此代码......

childform  obj = new childform( );
               obj.MdiParent = this;
               obj.StartPosition = FormStartPosition.CenterScreen;
               obj.Show( );

write this code in a parent form....

childform  obj = new childform( );
               obj.MdiParent = this;
               obj.StartPosition = FormStartPosition.CenterScreen;
               obj.Show( );
冰葑 2024-10-14 11:37:09
class MainClass
{
   public string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
   public void showWindow(Form openWin, Form closeWin, Form MDI)
    {
        closeWin.Close();
        openWin.WindowState = FormWindowState.Minimized;
        openWin.MdiParent = MDI;
        openWin.Show();
    }
}
class MainClass
{
   public string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
   public void showWindow(Form openWin, Form closeWin, Form MDI)
    {
        closeWin.Close();
        openWin.WindowState = FormWindowState.Minimized;
        openWin.MdiParent = MDI;
        openWin.Show();
    }
}
江南烟雨〆相思醉 2024-10-14 11:37:08

要从另一个子级创建子级,只需这样编写:

ChildForm sibling = new ChildForm();
sibling.MdiParent = this.MdiParent;
sibling.Show();

或者触发父级可以响应的自定义事件。

To create a child from another child, just write it like this:

ChildForm sibling = new ChildForm();
sibling.MdiParent = this.MdiParent;
sibling.Show();

Or fire a custom event that the parent can respond to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文