Locate mouse position of hovered tabpage

I'm creating a tabbed browser app where each page is dynamically created and named. I need to use the mousehover event but don't know how to determine which tabpage is in the hover state. VB.NET documentation mentions the MouseEventArgs class but when I try to add a new mousehover delegate, VB will not accept this signiture in place of the required System.EventArgs.

Bottom line: the app contains a main form with a 'New Tab' checkbox. If checked and address bar URL is navigated, a new tabpage is dynamically added to the tabcontrol and named "wbTabPage" & << the new tab's index >>. I want to raise the mousehover event whenever this new dynamically created tabpage is hovered.

I searched for three days for information with no workable results. Help!




Answer this question

Locate mouse position of hovered tabpage

  • eldiener

    On second thought, if you have a webbrowser in the tab, you are

    actually hovering over a webbrowser and webbrowser does not

    let you control the hover event. See:

    ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/cpref17/html/T_System_Windows_Forms_WebBrowser_Events.htm

    If you meant the top portion of the tab being hovered, my code does not work for that,

    but there may be a way to do it.



  • hayek85

    This code works with a 'manually' created new tab.

    Option Strict Off

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim TabPage3 As New System.Windows.Forms.TabPage

    TabPage3.Name = "tabpage3"

    Me.TabControl1.Controls.Add(TabPage3)

    AddHandler TabPage3.MouseHover, AddressOf NewTabs_MouseHover

    End Sub

    Private Sub NewTabs_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs)

    MsgBox(sender.name)

    End Sub

    End Class



  • emepvsd

    Okay, heres an example that seems to work with

    the top part of the tab.

    Option Strict Off

    Public Class Form1

    ' Sets a label text to the currently 'hovered' tab

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim TabPage3 As New System.Windows.Forms.TabPage

    TabPage3.Name = "tabpage3"

    Me.TabControl1.Controls.Add(TabPage3)

    End Sub

    Private Sub TabControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseMove

    Dim index As Int32

    For index = 0 To TabControl1.TabCount - 1

    If TabControl1.GetTabRect(index).Contains(e.X, e.Y) Then

    TabControl1.SelectedIndex = index

    Exit For

    End If

    Next

    Label1.Text = TabControl1.TabPages(index).Name

    End Sub

    End Class



  • David d48701

     

    Thankyou!  Its not the hover event but I can write a code work-around for that.  The example you gave put a new tool in my bag.

    Specifically:

    wbTabControl1.GetTabRect(index).Contains(e.X, e.Y)

     

    This is exactly what I was looking for - Awesome!  I wish you well in your job hunt.



  • Bibek

    Thank you.

  • Locate mouse position of hovered tabpage