vb.net 如何使用 MDI 父窗体制作 mdi 子窗体?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14867357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make mdi child forms using MDI parent form?
提问by user1945423
i made 15 form in my project after that i made home form a parent MDI from by giving property isMDIparent true.now i want to make all form as child form of home form but i dont no way to do.so please suggest me code to assign all form to make child form of parentMDI home form.
我在我的项目中制作了 15 个表格,之后我通过赋予属性 isMDIparent true 制作了一个父 MDI 的家庭表格。现在我想将所有表格制作为家庭表格的子表格,但我没有办法做。所以请建议我代码分配所有表单以制作 parentMDI 主表单的子表单。
回答by Mark Hall
You need to set the child Form's MdiParent Propertyto your MdiContainer. This example assumes two Forms one named Form1 and the other named Form2. All properties are being set programmatically.
您需要将子窗体的MdiParent 属性设置为您的 MdiContainer。此示例假设有两个 Form,一个名为 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
回答by PDX Geek
Here's the answer, straight from Microsoft:
这是直接来自微软的答案:
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
http://msdn.microsoft.com/en-us/library/vstudio/7aw8zc76(v=vs.100).aspx
回答by Ace of code
it is actualy this:
实际上是这样的:
Private sub new()
Dim c as form1 = new form1
c.owner = Me
c.MdiParent = Me
c.show
End sub
InitializeComponent()
does just what it says, it initializes a component. It is NOT for Mdichild
.
InitializeComponent()
做它所说的,它初始化一个组件。它不是为了Mdichild
.
回答by Prakash
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.
试试这个家伙..这是在 vb.net 中为 MDI 父级打开窗体作为 MDI 子级的代码。
回答by BINU NARAYANAN NELLIYAMPATHI
I think Mr.Mark Hall missed 1 property.., Try this.......
我认为 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