如何使用MDI父表单制作mdi子表单?

时间:2013-02-14 03:31:53

标签: vb.net

我在我的项目中制作了15个表格,之后我通过赠送属性isMDIparent true来制作家庭MDI。现在我想将所有形式作为家庭形式的子形式但是我没有办法做。所以请建议我将代码分配给所有表单以制作parentMDI主表单的子表单。

5 个答案:

答案 0 :(得分:1)

您需要将子表单的MdiParent Property设置为您的MdiContainer。此示例假定两个表单一个名为Form1,另一个名为Form2。所有属性都是以编程方式设置的。

Public Class Form1

    Public Sub New()

        InitializeComponent()
        Me.IsMdiContainer = True
        Dim frm2 As Form2 = New Form2
        frm2.Owner = Me
        frm2.MdiParent = Me
        frm2.Show()

    End Sub
End Class

答案 1 :(得分:1)

以下是答案,直接来自微软:

Protected Sub MDIChildNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
   Dim NewMDIChild As New Form2()
   'Set the Parent Form of the Child window.
   NewMDIChild.MdiParent = Me
   'Display the new form.
   NewMDIChild.Show()
End Sub

http://msdn.microsoft.com/en-us/library/vstudio/7aw8zc76(v=vs.100).aspx

答案 2 :(得分:0)

我认为Mr.Mark Hall错过了1处房产.., 试试这个.......

Public Class Form1

Public Sub New()

    InitializeComponent()
    Me.IsMdiContainer = True
    Dim frm2 As Form2 = New Form2
    frm2.Owner = Me
    frm2.MdiParent = Me.MdiParent
    frm2.Show()

End Sub

End Class

答案 3 :(得分:0)

实际上是这样的:

Private sub new()

Dim c as form1 = new form1
c.owner = Me
c.MdiParent = Me
c.show

End sub

InitializeComponent()正如它所说的那样,它初始化了一个组件。它不适用于Mdichild

答案 4 :(得分:0)

Private Sub HomeToolStripMenuItem_Click(sender As Object, e As EventArgs)
   Dim homechild As New login
   homechild.MdiParent = Me
   homechild.Dock = DockStyle.Fill
   homechild.Show()
End Sub

Try This Guys..Here Is the Code To Open A Form As MDI Child for an MDI Parent From in vb.net.