添加和删​​除TabControl com表单 [英] add and remove TabControl com forms

查看:108
本文介绍了添加和删​​除TabControl com表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看了很多地方,但发现不需要什么

事情是,我有一个TabControl TabControl,在这个内部

显然有TabPages TabPages并且在这些内表格有,

得到我的问题(noob),当我一次打开一个标签

工作正常,但当我离开一个开放的第二个她打开

形成以前的标签形式...

我很困惑吧!

为了更好地理解项目已经发布...... 。

对于参加测试的人来说,标签客户端上的菜单按钮会打开一个查询。

产品标签按钮打开另一个查询。



我用来打开的代码:



I have looked in many places, but found no need WHAT
The thing is, I have a TabControl TabControl and within this
obviously have TabPages TabPages and within these forms have, there is
getting my problem (noob), when I open a tab at a time
works fine, but when I leave an open and open the second she opens
form the previous form of tab ...
I am very confused right!
To better understand the project have released ....
for anyone taking the test, the menu button on the tab client opens a query.
products tab button opens a further query.

The code I use to open:

Public Sub opensForm2 ()
        If testa_aberto_frm2 = True Then
            The Dim Form2 f2 = New Form2
            f2.Focus ()
        Else
            The Dim Form2 f2 = New Form2
            f2.TopLevel = False
            Form1.TabControl1.TabPages.Add (f2.Text)
            Form1.TabControl1.SelectedTab.Controls.Add (f2)
            f2.Show ()
            test_open_frm2 = True
        End If
    End Sub

    Public Sub openform3 ()
        If teste_aberto_frm3 = True Then
            Dim f3 as Form3 = New Form3
            f3.Focus ()
        Else
            Dim f3  as Form3 = New Form3 
            f3.TopLevel = False
            Form1.TabControl1.TabPages.Add (f3.Text)
            Form1.TabControl1.SelectedTab.Controls.Add (f3)
            f3.Show ()
            test_open_frm3 = True
        End If
    End Sub



关闭:




to close:

Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f3 = The New Form3 Form3
        f3.Close ()
        Form1.TabControl1.TabPages.Remove (Form1.TabControl1.SelectedTab)
        test_open_frm3 = False
    End Sub

    Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   Dim  f2 as Form2= New Form2
        f2.Close ()
        Form1.TabControl1.TabPages.Remove (Form1.TabControl1.SelectedTab)
        test_open_frm2 = False
    End Sub



我感谢




I thank

推荐答案

我为你写了一个简单的类来添加和删除标签(带表格)。解决方案并不完美......你需要记住:这是一个例子!



实现解决方案的步骤:

1)我们需要一个界面 [ ^ ]

I wrote for you a simple class to add and removes tabs (with forms). The solution is not perfect... You need to remember: this is an example!

Steps to achieve a solution:
1) We need an interface[^]
Public Interface IFormsInTabs

    Function AddTab(ByVal frm As Windows.Forms.Form) As Integer 'to add new tab with form inside ;)
    Function RemoveTab() As Integer 'to close current tab

End Interface





2)我们需要 [ ^ ]从接口实现方法,函数(和其他东西)。



2) We need a class[^] which implements methods, functions (and other stuff) from interface.

Public Class TFormsInTabs
    Implements IFormsInTabs

    Private oTc As TabControl = Nothing 'we store a TabControl (from Form) in our class

    Public Sub New(ByVal _tc As TabControl)
        oTc = _tc '
    End Sub

    Public Function AddTab(ByVal frm As System.Windows.Forms.Form) As Integer Implements IFormsInTabs.AddTab
        Dim oTp As TabPage = Nothing 'a tabpage to add into TabControl

        Try
            oTp = New TabPage(frm.Text)
            frm.TopLevel = False
            oTp.Controls.Add(frm)
            frm.Dock = DockStyle.Fill
            frm.Show()
            oTc.TabPages.Add(oTp)
            oTc.SelectedTab = oTp

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error... {AddTab}")

        Finally
            oTp = Nothing
        End Try

    End Function

    Public Function RemoveTab() As Integer Implements IFormsInTabs.RemoveTab
        Try
            'removes current tab
            oTc.TabPages.Remove(oTc.SelectedTab)

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error... {RemoveTab}")
        End Try

    End Function

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

End Class





3)实现(使用TabControl的形式):



3) Implemetation (in the form with TabControl):

Public Class MainFrm

    Dim mTC As IFormsInTabs = Nothing 'declare variable to store our class (using interface)

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        mTC = New TFormsInTabs(Me.TabControl1) 'here we call Public Sub New(Byval _tc As TabControl) in our class

    End Sub

    Private Sub TSMIOpenForm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSMIOpenForm1.Click
        Dim frm As Form1 = New Form1

        mTC.AddTab(frm)
        Me.TabControl1.Refresh()
    End Sub

    Private Sub TSMIOpenForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TSMIOpenForm2.Click
        Dim frm As Form2 = New Form2

        mTC.AddTab(frm)
        Me.TabControl1.Refresh()
    End Sub


    Private Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        mTC.RemoveTab()
        Me.TabControl1.Refresh()
    End Sub


    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub

End Class





我希望它会我会有所帮助(如果是的话,请给它评分)。如果您有任何疑问,请告诉我(使用有问题......小部件)。



I hope it will be helpful (if yes, please rate it). If you have any question, please let me know (use "Have a Question ..." widget).


谢谢Sir It Works。

我给5五星之星。
Thanks Sir It Works.
I give 5 star Out Of Five Star.


这篇关于添加和删​​除TabControl com表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆