TabControl / TabPage

TJCirco

New member
Joined
Oct 26, 2005
Messages
2
Programming Experience
Beginner
Good day,
I am trying to accomplish something similar to the Excel sheet layout in VB.net where you can have variable amounts of tabs(sheets) and when you RIGHT click you are then able to set focus to that tab and have a context menu appear. I use a MouseDown event to trigger the action but am not able to set focus to the desired tab. Any suggestions to accomplish this task would be much appreciated.
 
TabControl/TabPage

To answer my own question. I found that if i could trap the point where the right click was made I could ultimately associate the underlying tabpage.

This is what has worked for me so far and may or may not work for you. So use at your own risk.

Private Sub TabControl1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseUp
'Get the point from the current Right mouse click
Dim RClickPoint As New Point(e.X, e.Y)
'Initialize Tab page index
Dim tpIndex As Integer
'Initialize holding index
Select Case e.Button
Case MouseButtons.Right
'Decrement for closed pages
Label2.Text = Label2.Text - 1
'Set Tab page index initially to 0 and count the # of Tab pages
For tpIndex = 0 To TabControl1.TabPages.Count - 1
'Condition: get the Tab page that contains the right click coordinates
If TabControl1.GetTabRect(tpIndex).Contains(RClickPoint) Then
'Select the Tab page that contains the rect. coordinates
TabControl1.SelectedTab = TabControl1.TabPages(tpIndex)
Exit For
End If
Next
End Select
End Sub


**I added a context menu to handle the deletion like in an Excel sheet**


Private Sub DeletePage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeletePage.Click
'Delete

TabControl1.TabPages.RemoveAt(Label1.Text)
activeChild.Close()
End Sub
 
Back
Top