在第二个MDI子项关闭后,防止显示MDI子标题栏

时间:2016-03-09 07:10:48

标签: vb.net forms mdi

在Win Form MDI应用程序中,我希望MDI子窗体在父容器中显示为最大化,而没有自己的标题栏。一切正常,直到我从第一个子表单打开第二个子表单,然后关闭第二个子表单 - 然后显示第一个子表单的标题栏。

我创建了一个包含三种形式的小测试项目 - frmParent,frmChild1和frmChild2。 frmParent包含一个MenuStrip,其中包含打开frmChild1,打开frmChild2和exit的选项。 FrmChild1包含两个按钮 - 打开frmChild2和Close。 frmChild2包含一个单独的按钮。

frmParent代码:

Private Sub mnuChild1_Click(sender As Object, e As EventArgs) Handles mnuChild1.Click
    Dim lfrmChild1 As New frmChild1
    lfrmChild1.MdiParent = Me
    lfrmChild1.WindowState = FormWindowState.Maximized
    lfrmChild1.Show()
End Sub

Private Sub mnuChild2_Click(sender As Object, e As EventArgs) Handles mnuChild2.Click
    Dim lfrmChild2 As New frmChild2
    lfrmChild2.MdiParent = Me
    lfrmChild2.WindowState = FormWindowState.Maximized
    lfrmChild2.Show()
End Sub

Private Sub mnuExit_Click(sender As Object, e As EventArgs) Handles mnuExit.Click
    Me.Close()
End Sub

frmChild1代码:

Private Sub btnCloseChild1_Click(sender As Object, e As EventArgs) Handles btnCloseChild1.Click
    Me.Close()
End Sub

Private Sub btnOpenChild2_Click(sender As Object, e As EventArgs) Handles btnOpenChild2.Click
    Dim lfrmChild2 As New frmChild2
    lfrmChild2.MdiParent = Me.MdiParent
    lfrmChild2.WindowState = FormWindowState.Maximized
    lfrmChild2.Show()
End Sub

Private Sub frmChild1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.StartPosition = FormStartPosition.Manual
    Me.WindowState = FormWindowState.Maximized
    Me.MaximizeBox = False
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End Sub

frmChild2代码:

Private Sub btnCloseChild2_Click(sender As Object, e As EventArgs) Handles btnCloseChild2.Click
    Me.Close()
End Sub

Private Sub frmChild2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.StartPosition = FormStartPosition.Manual
    Me.WindowState = FormWindowState.Maximized
    Me.MaximizeBox = False
End Sub

从frmChild1打开后,如何阻止frmChild2关闭后显示frmChild1的标题栏?

0 个答案:

没有答案