Results 1 to 2 of 2

Thread: Removing Tabpage With MiddleClick

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2010
    Posts
    21

    Removing Tabpage With MiddleClick

    Code:
    Public Class Form1
    
        Private m_MouseCoords As Point
    
        Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseClick
            If e.Button = Windows.Forms.MouseButtons.Middle Then
                If TabControl1.TabPages.Count > 0I Then
                    Dim TabPageIndex As Integer = -1I
                    For Counter As Integer = 0I To TabControl1.TabPages.Count - 1I
                        If TabControl1.GetTabRect(Counter).Contains(m_MouseCoords) Then
                            TabPageIndex = Counter
                        End If
                    Next Counter
                    If TabPageIndex > -1I Then
                        TabControl1.TabPages.RemoveAt(TabPageIndex)
                        If TabControl1.TabPages.Count > 0I Then TabControl1.SelectedIndex = 0I 'Selects the first one
                    End If
                End If
            End If
        End Sub
    
        Private Sub TabControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseDown
            If e.Button = Windows.Forms.MouseButtons.Middle Then m_MouseCoords = New Point(e.X, e.Y)
        End Sub
    
        Private Sub TabControl1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseUp
            m_MouseCoords = Nothing
        End Sub
    
    End Class
    So I was tinkering with my tabpages and removing them with my middle click and I came across a problem:
    Make a new form with this code and then make a tabcontrol with 8 tabs, run it and click tabpage8 then tabpage7 and then try to remove tabpage4; unfortunately it removes tabpage3. Any help is appreciated, thanks!

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Feb 2010
    Posts
    21

    Re: Removing Tabpage With MiddleClick

    Anyone know?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width