2016-11-17 189 views
-1

我正在使用Windows应用程序。我有一个MainForm(父)和几个childForm。在MainForm中有一个列表视图,其中包含一个childForm名称列表,并通过单击列表中的每个名称,显示相关的childForm,并关闭以前的ChildForm。如何从另一个孩子窗体打开孩子窗体?

我使用这个代码,以显示childForm和关闭在MainForm.cs(ParentForm)先前childForm:

CloseForms(); 
frm_draft = new frm_ShowDraft(); 
frm_draft.MdiParent = this; 
frm_draft.Show(); 

CloseForm()是用于检查的方法,该childForm运行过程中出现并且关闭它。 到目前为止,一切都很好。

在其中一个子表单中有一个按钮。当用户点击它时,它应该关闭这个childForm并显示另一个。但是当我点击按钮时,childForm2显示出MainForm。我如何在MainForm中显示它?

我在按钮的点击事件代码:

this.close(); 
frm_c2 = new frm_child2(); 
frm_c2.MdiParent = new MainForm().ParentForm; /// Or this.MdiForm 
frm_c2.Show(); 
+0

如果这是'C#'为什么你使用'VB.NET'标签? – Bugs

+0

看看[这里](http://stackoverflow.com/questions/8566582/how-to-centerparent-a-non-modal-form/8566716#8566716)。 – dee

+0

@ Jinx88909 VB.NET标记? – saedbfd

回答

0

http://www.independent-software.com/weifenluo-dockpanelsuite-tutorial-cookbook/

要显示在主窗体子窗体使用魏风罗库。 这种控制将使其更容易对接的形式进入主窗体的Visual Studio对接屏幕

形成内3种形式:

enter image description here

确保IsMdiContainter道具是真的。

enter image description here

实施例:

public Form1() 
{ 
    InitializeComponent(); 

    Form2 f2 = new Form2(); // create new form 

    // dockPanel is an control from WeiFen Luo more info see the link 
    // dockPanel control is docked in your mainform. 
    // this will open Form2 in the dockPanel and align it left 
    f2.Show(dockPanel, DockState.DockLeft); 

} 

更多对接选项:

  1. DockState.Fill码头形成在空穴DockPanel中
  2. DockState.Right码头在DockPanel中
  3. DockState.Top码头的rightside形成在形成的DockPanel中

更多选项顶面检查链接 这种控制将韩德尔的对接形式responsifnes并会为您处理所有定位计算。

+0

是的,我设置IsMdiContainer = True – saedbfd

+0

如果您尝试使用ShowDialog()而不是.Show(); –

+0

但我想在MainForm里面显示childForm。 ShowDialog()作为父母而不是孩子开放。 – saedbfd

2

您应该设置相同的mdi窗体,并在年底关闭致电:

frm_c2 = new frm_child2(); 
frm_cLetter.MdiParent = this.MdiParent; 
frm_cLetter.Show(); 
this.Close(); 
+0

我的问题是childForm2显示像父窗体而不是childForm。我如何显示childForm2像MainForm里面的childForm? – saedbfd

+0

把this.Close()后frm_cLetter.Show() – Shadowed

+0

我把this.Close()在最后。但显示childForm2出MainForm但 – saedbfd

相关问题