Vb.net 如何将单击侦听器添加到以编程方式添加的Tabcontrol

Vb.net 如何将单击侦听器添加到以编程方式添加的Tabcontrol,vb.net,visual-studio-2010,Vb.net,Visual Studio 2010,在我的应用程序中,我以编程方式添加了如下选项卡: 'show searchresults tab if not present If Not TabControl1.TabPages.Contains(tabSearchresults) Then TabControl1.TabPages.Insert(3, tabSearchresults) End If 现在,我似乎无法在“设计”视图中手动将单击事件侦听器添加到该选项卡,而当我在“代码视图”中这样做时,单击该选项卡时不会发生任何事情

在我的应用程序中,我以编程方式添加了如下选项卡:

'show searchresults tab if not present
If Not TabControl1.TabPages.Contains(tabSearchresults) Then
    TabControl1.TabPages.Insert(3, tabSearchresults)
End If
现在,我似乎无法在“设计”视图中手动将单击事件侦听器添加到该选项卡,而当我在“代码视图”中这样做时,单击该选项卡时不会发生任何事情


所以问题是,。。如何将单击侦听器添加到该选项卡SearchResults选项卡?

我假设您的
选项卡SearchResults
就是您的
选项卡页面

因此,首先创建一个函数,它将作为
Click
事件的处理程序

Private Sub tabSearchresults_Click(sender as Object, e as EventArgs)
    'your code ...
End Sub
然后在初始化
选项卡页面的第行之后添加此处理程序:

tabSearchresults = New TabPage()
AddHandler tabSearchresults.Click, AddressOf tabSearchresults_Click

请看以下问题: