Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change SelectedTab of TabControl on MouseOver

I have a Windows Forms project with a TabControl.

Does anyone know how to change the SelectedTab when you hover over it with the pointer?

like image 582
MANISHDAN LANGA Avatar asked Jan 18 '23 06:01

MANISHDAN LANGA


2 Answers

You can use TabControl's MouseMove event to detect whether your mouse is present on any tab and then can select it:

private void tabControl1_MouseMove(object sender, MouseEventArgs e)
{
    Rectangle mouseRect = new Rectangle(e.X, e.Y, 1, 1);
    for (int i = 0; i < tabControl1.TabCount; i++)
    {
        if (tabControl1.GetTabRect(i).IntersectsWith(mouseRect))
        {
            tabControl1.SelectedIndex = i;
            break;
        }
    }
}
like image 96
Coder Avatar answered Jan 27 '23 22:01

Coder


Try this:

private void tabControl1_MouseMove(object sender, MouseEventArgs e)
    {
        for (int i = 0; i < tabControl1.TabCount; i++)
        {
            if (tabControl1.GetTabRect(i).Contains(e.X, e.Y))
            {
                tabControl1.SelectedIndex = i;
                break;
            }
        }
    }
like image 39
ionden Avatar answered Jan 27 '23 22:01

ionden