本文介绍了TabControl的事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试触发两个动态tabcontrol的click事件.我无法在第一个asign tabcontrol中触发点击事件. (无数组)
Hello All,
I m trying to fire click event of two dynamic tabcontrols. i am not able to fire click event in the first asign tabcontrol. (without array)
Public Class Form1
Friend WithEvents MaxTab As TabControl
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
''dataentry
MaxTab = New TabControl
MaxTab.Name = "tabd"
MaxTab.Top = 1
MaxTab.Size = New System.Drawing.Size(Me.Width - 15, Me.Height - 80)
MaxTab.TabPages.Add("dTAB1")
MaxTab.TabPages.Add("dTAB2")
AddHandler MaxTab.Click, AddressOf MaxTab_Click
Me.Controls.Add(MaxTab)
''Report
MaxTab = New TabControl
MaxTab.Name = "tabr"
MaxTab.Top = 1
MaxTab.Size = New System.Drawing.Size(Me.Width - 15, Me.Height - 80)
MaxTab.TabPages.Add("rTAB1")
MaxTab.TabPages.Add("rTAB2")
AddHandler MaxTab.Click, AddressOf MaxTab_Click
Me.Controls.Add(MaxTab)
Me.Controls("tabr").Visible = False
Me.MaxTab.Refresh()
End Sub
Private Sub MaxTab_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MaxTab.Click
MessageBox.Show(MaxTab.SelectedTabPage.Text)
End Sub
End Class
推荐答案
Public Class Form1
Friend WithEvents MaxTab As TabControl
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
''dataentry
MaxTab = New TabControl
MaxTab.Name = "tabd"
MaxTab.Top = 1
MaxTab.Size = New System.Drawing.Size(Me.Width - 15, Me.Height - 80)
MaxTab.TabPages.Add("dTAB1")
MaxTab.TabPages.Add("dTAB2")
AddHandler MaxTab.MouseDown, AddressOf tabs_MouseDown
Me.Controls.Add(MaxTab)
''Report
MaxTab = New TabControl
MaxTab.Name = "tabr"
MaxTab.Top = 1
MaxTab.Size = New System.Drawing.Size(Me.Width - 15, Me.Height - 80)
MaxTab.TabPages.Add("rTAB1")
MaxTab.TabPages.Add("rTAB2")
Me.Controls.Add(MaxTab)
Me.Controls("tabr").Visible = False
Me.MaxTab.Refresh()
End Sub
'here's where you get the tab page...
Private Sub tabs_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MaxTab.MouseDown
Dim r As Rectangle
Dim ll As Integer
For ll = 0 To MaxTab.TabPages.Count - 1
r = MaxTab.GetTabRect(ll)
If e.X >= r.Left And e.X <= r.Right And e.Y >= r.Top And e.Y <= r.Bottom Then
MsgBox(MaxTab.TabPages(ll).Text)
Exit For
End If
Next
End Sub
End Class
这篇关于TabControl的事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!