在TabPage中关闭带有表单的TabPage [英] Close TabPage with Form in TabPage
问题描述
您好。
我有一个普通的表格作为主要表格,里面有一个TabControl。当我打开一个子表单时,我把它放到一个TabPage中并将TabPage添加到TabControl中。
我有很多包含关闭表单按钮的子表单。用户可以按按钮关闭表单。但是如果此表单显示在TabPage中,则在关闭表单后,TabPage将为空白。它可能不太好。
当我同时关闭子表单时如何删除TabPage?
Hello.
I have a normal form as main form with a TabControl in it. When I opened a child form, I put it into a TabPage and add the TabPage into the TabControl.
I have many child forms containing a close form button. Users may press the button to close the form. But if this form is shown in a TabPage, after the form is being closed, the TabPage will be blank. It may not be good.
How can I remove the TabPage when I close the child form at the same time?
推荐答案
如果我正确理解你
if i understand you correctly
Sub addFormToTab()
'add the form to your tab
Dim frm As New Form
frm.TopLevel = False
frm.Parent = TabPage1
frm.Size = TabPage1.Size
frm.StartPosition = FormStartPosition.CenterParent
'add a handler for form closed event, specific to the form you just added
AddHandler frm.FormClosed, AddressOf CloseTabThatBelongsToSender
'show the form on your tab
''P.S. I just learned how to add forms to tabs. Good concept, never thought of it.
frm.Show()
End Sub
'this is the sub routine that your event handler refers to
Sub CloseTabThatBelongsToSender(Sender As Form, e As System.Windows.Forms.FormClosedEventArgs)
'declare a variable of tab page type and set it equal to
'the parrent of the for that threw the event
Dim x As TabPage = Sender.Parent
'you need the parent to be declared as a TabPage(which is what it is) so that you can do this
TabControl1.TabPages.Remove(x)
End Sub
我喜欢这些面向对象,事件驱动的应用程序......
I do love these Object Oriented, Event Driven applications.....
这篇关于在TabPage中关闭带有表单的TabPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!