• 0

[vb .net] Right click on unselected tab and close?


Question

Ok, I am having ah ard time figuring this out and was hoping your minds could find a solution. I have a tab control with nonfixed sized tabs. I want to be able to right click on a nonselected tab, bring up the tab control context menu, and close it via the menu options. Unfortunately, I have no idea how to grab the index of the tab when it's not the selected tab. Does anyone have an idea how to grab that index value?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

I've done something similar...

i created my own tabcontrol that adds an "X" next to the tab's caption and if you click that X it closes the tab. If you click elsewhere it opens the tab normally.

I'll check the code if I can find it then post it here.

Link to comment
Share on other sites

  • 0

I found it, but it's not really what you asked for... Might give you some ideas, though...

This piece of code was on the MouseDown event of an inherited tab control.

       Dim pt As New Point(e.X, e.Y)
 ? ? ?For i = 0 To Me.TabPages.Count - 1
 ? ? ? ? ? ?If Me.GetTabRect(i).Contains(pt) Then Exit For
 ? ? ? ?Next
 ? ? ? ?rec = Me.GetTabRect(i)


'What does it do? It checks to see what tab contains the point (x,y) that is the mouse cursor. Rec becomes the tabpage the mouse is over.

 ? ? ? ? ? ? ? ?If Me.TabPages.Count = 1 Then
 ? ? ? ? ? ? ? ? ? ?MsgBox("There is only one visible tab", MsgBoxStyle.Information)
 ? ? ? ? ? ? ? ? ? ?Exit Sub
 ? ? ? ? ? ? ? ?End If

'This part ensures that there is ALWAYS at least one visible tab. Might be useful in certain programs

 ? ? ? ? ? ? ? ?Me.TabPages.RemoveAt(i)

'Removes that tab.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.