试试下面的代码,然后......
1 - 更改 MENU 的名称,因为在我的示例中 menuitem 被称为“Form7ToolStripMenuItem_Click”
2 - 确保将其粘贴到 MDIFORM 中,而不仅仅是基本 FORM
然后让我知道 CHILD 表单是否仍显示在父表单之外
Private Sub Form7ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form7ToolStripMenuItem.Click
Dim NewForm As System.Windows.Forms.Form
NewForm = New System.Windows.Forms.Form
'USE THE NEXT LINE - to add an existing CUSTOM form you already have
'NewForm = Form7
NewForm.Width = 400
NewForm.Height = 250
NewForm.MdiParent = Me
NewForm.Text = "CAPTION"
NewForm.Show()
DockChildForm(NewForm, "left") 'dock left
'DockChildForm(NewForm, "right") 'dock right
'DockChildForm(NewForm, "top") 'dock top
'DockChildForm(NewForm, "bottom") 'doc bottom
'DockChildForm(NewForm, "full") 'fill the client area (maximise the child INSIDE the parent)
'DockChildForm(NewForm, "Anything-Else") 'center the form
End Sub
Private Sub DockChildForm(ByRef Form2Dock As Form, ByVal Position As String)
Dim XYpoint As Point
Select Case Position
Case "left"
Form2Dock.Dock = DockStyle.Left
Case "top"
Form2Dock.Dock = DockStyle.Top
Case "right"
Form2Dock.Dock = DockStyle.Right
Case "bottom"
Form2Dock.Dock = DockStyle.Bottom
Case "full"
Form2Dock.Dock = DockStyle.Fill
Case Else
XYpoint = New Point
XYpoint.X = ((Me.ClientSize.Width - Form2Dock.Width) / 2)
XYpoint.Y = ((Me.ClientSize.Height - Form2Dock.Height) / 2)
Form2Dock.Location = XYpoint
End Select
End Sub