如何使SplitContainer1.Panel2作为所有子窗体的父级? [英] How to make SplitContainer1.Panel2 as Parent For All Child Forms?

查看:164
本文介绍了如何使SplitContainer1.Panel2作为所有子窗体的父级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3种形式

Form1作为Mdicontainer
form2
Form3

Form1具有SplitContainer1,Treeview1控件,并且form1正在运行
作为MdiContainer

Treeview1放置在Splitcontainer1.Panel1内,其中Dock为填充

form2-Button1,Button2:
在form1加载事件中,我已经编写了显示Form2的代码

I have 3 forms

Form1 as Mdicontainer
form2
Form3

Form1 has SplitContainer1,Treeview1 Controls and form1 is acting
as MdiContainer

Treeview1 is placed inside Splitcontainer1.Panel1 With Dock as Fill

form2 - Button1,Button2:
in form1 load event i have written the code to show Form2

form2 f = new form2();
f.MdiParent = this;
f.Parent = this.splitContainer1.Panel2;
f.FormBorderStyle = FormBorderStyle.None;
f.ShowInTaskbar = false;
f.Dock = DockStyle.Fill;
f.StartPosition = FormStartPosition.CenterScreen;
f.Show();


它完美地显示了form2.

当我单击Button1(form2)时,我想向Form3展示,就像我如何编写代码以显示Form2一样.

有什么想法让我真诚地知道.

问候,
Pawan.


It shows the form2 Perfectly..

When i click on Button1(form2), i want to show Form3 like how i wrote the code to show form2.

have any idea do let me know sincerely.

Regards,
Pawan.

推荐答案

好,您需要在主(MDI)表单上公开一个方法.人们普遍认为,公开控件本身是不好的做法.
创建一个公共方法,例如AddToPanel(Form f, ?? panelToAddTo)(或类似的东西),其中包含您发布的代码的版本.
您可以通过其Parent属性进入主表单.

干杯
Well, you need to expose a method on you main (MDI)form. It''s generally accepted that exposing the controls themselves is bad practice.
Create a public method like AddToPanel(Form f, ?? panelToAddTo) (or something similar) that contains a version of the code you posted.
You can get to the main form by it''s Parent property.

Cheers


这篇关于如何使SplitContainer1.Panel2作为所有子窗体的父级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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