VB.NET - TabControl 中的表单在关闭后未打开
VB.NET - Form in TabControl not opened after closing It
我在打开表单的地方有 ToolStripMenu。表单在 TabControl 中打开,它位于 Split Container 的面板之一。我也在 Split 容器中放置了一个按钮,它会关闭所有选定的 TabPages(表单打开的地方)。问题是,当我在新 TabPage 中打开表单并通过此按钮关闭它时,表单不再打开。为什么 ? ....这是我的代码:
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
该对象已经存在,只是隐藏了,而您又要创建它,请在重新创建之前销毁该对象。
Dim tbp As TabPage = TabControl1.SelectedTab
TabControl1.TabPages.Remove(tbp)
tbp.Dispose()
我在打开表单的地方有 ToolStripMenu。表单在 TabControl 中打开,它位于 Split Container 的面板之一。我也在 Split 容器中放置了一个按钮,它会关闭所有选定的 TabPages(表单打开的地方)。问题是,当我在新 TabPage 中打开表单并通过此按钮关闭它时,表单不再打开。为什么 ? ....这是我的代码:
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
该对象已经存在,只是隐藏了,而您又要创建它,请在重新创建之前销毁该对象。
Dim tbp As TabPage = TabControl1.SelectedTab
TabControl1.TabPages.Remove(tbp)
tbp.Dispose()