我從打開窗體的地方獲取ToolStripMenu。表格在TabControl中打開,放置在Split Container的一個面板中。我也在Split容器中放置了一個按鈕,它關閉了任何選定的TabPages(其中表單打開)。問題是,當我在新的TabPage中打開窗體並通過此按鈕關閉它時,窗體不再打開。爲什麼? ....這裏是我的代碼:VB.NET - TabControl中的表格在關閉後未打開它
Private Sub SearchItemsAPOToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SearchItemsToolStripMenuItem.Click
'Define new page in Tab control and form to open in It
Dim PageNew As New TabPage()
Dim FrmItem As New Search_Items
'Define where and how form should open
FrmItem.TopLevel = False
FrmItem.Dock = DockStyle.Fill
FrmItem.FormBorderStyle = FormBorderStyle.None
'If form allready opened in TabPage, only send focus to It
If Application.OpenForms().OfType(Of Search_Items).Any Then
For Each page As TabPage In TabControl1.TabPages
If page.Text = "Search Items" Then
TabControl1.SelectedTab = page
End If
Next page
'If form not allready opened, we open It in Tab control and send focus on that TabPage
Else
PageNew.Controls.Add(FrmItem)
PageNew.Text = "Search Items"
TabControl1.Visible = True
TabControl1.TabPages.Add(PageNew)
FrmItem.Show()
BtnTab.Visible = True
TabControl1.SelectedTab = PageNew
End If
End Sub
Private Sub BtnTab_Click(sender As Object, e As EventArgs) Handles BtnTab.Click
'Button is visible when TabPages are opened, and with click It closes selected TabPage
Me.TabControl1.TabPages.Remove(Me.TabControl1.SelectedTab)
'IF no TabPages, button hides again
If TabControl1.TabPages.Count = 0 Then
TabControl1.Visible = False
BtnTab.Visible = False
End If
End Sub
爲什麼要刪除選定的選項卡而不是隱藏它? –
@Alex B.您無法隱藏標籤 – SSS
Search_Items究竟是什麼?一個'UserControl'也許? –