选项卡页面面板上的VB.NET停靠表单

时间:2018-03-03 18:26:46

标签: vb.net

如何在标签页内的面板中添加表单? 我使用此代码来执行此操作,但是当我调整主窗体的大小时,标签页内的表单不会自动调整大小。

Public Sub showForm(ByVal frm As MetroForm)
    Dim a As New Panel

    For i As Integer = 0 To tabPage.TabCount - 1
        If frm.Text = tabPage.TabPages(i).Text Then
            tabPage.SelectedIndex = i
            Exit Sub
        End If
    Next

    a = New Panel
    tabPage.TabPages.Add("")
    tabPage.TabPages(tabPage.TabPages.Count - 1).Controls.Add(a)
    a.Dock = DockStyle.Fill
    frm.TopLevel = False
    frm.MinimizeBox = False
    frm.MaximizeBox = False
    frm.DisplayHeader = False
    frm.AutoSize = False
    frm.Dock = DockStyle.Fill

    tabPage.TabPages(tabPage.TabPages.Count - 1).Text = frm.Text
    a.Visible = True
    a.Name = "pnl" & frm.Name
    a.Controls.Add(frm)
    frm.Dock = DockStyle.Fill
    frm.Visible = True
    frm.BringToFront()

    AddHandler a.ControlRemoved, AddressOf Me.removePanel
    tabPage.SelectedIndex = tabPage.TabPages.Count - 1
    tabPage.TabPages(tabPage.TabPages.Count - 1).Name = frm.Text
End Sub

并在表单关闭时删除标签页:

Private Sub removePanel(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim a As Panel = DirectCast(sender, Panel)
    For Each obj As TabPage In tabPage.TabPages
        If obj.Name = sender.Parent.Name Then
            obj.Controls(0).Dispose() 'remove form
            tabPage.TabPages.Remove(obj) 'remove tab page
            RemoveHandler a.ControlRemoved, AddressOf Me.removePanel
        End If
    Next
End Sub

这是截图: Before Resize After Resize

0 个答案:

没有答案