Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow switching tabs with scroll wheel. #159

Open
DrewNaylor opened this issue Mar 24, 2020 · 1 comment
Open

Allow switching tabs with scroll wheel. #159

DrewNaylor opened this issue Mar 24, 2020 · 1 comment

Comments

@DrewNaylor
Copy link
Owner

DrewNaylor commented Mar 24, 2020

Code available in this Gist:
https://gist.github.com/DrewNaylor/b2d79180090f8fd5d1dfd0dda2d39c06

Copied here in case something happens to it:

    Private Sub tabcontrolAboutWindow_MouseWheel(sender As Object, e As MouseEventArgs) Handles tabcontrolAboutWindow.MouseWheel
        ' Getting the mouse scroll direction was based on this SO answer:
        ' https://stackoverflow.com/a/2378365

        ' Allows the tabs to be scrolled with the mouse, like in many
        ' Linux applications.
        ' Perhaps this could be made into a sub with args for easier reuse.

        ' Ensure the mouse isn't in the tabpage itself.
        ' This is based on this SO answer:
        ' https://stackoverflow.com/a/21098227
        Dim tabpage As TabPage = tabcontrolAboutWindow.SelectedTab
        If Not tabpage.ClientRectangle.Contains(tabpage.PointToClient(Control.MousePosition)) Then

            If e.Delta > 0 Then
                ' If scrolling down, go left.
                If tabcontrolAboutWindow.SelectedIndex - 1 = -1 Then
                    ' If the next tab is out of bounds, select the last tab.
                    tabcontrolAboutWindow.SelectTab(tabcontrolAboutWindow.TabCount - 1)
                Else
                    ' Otherwise, select the tab to the left.
                    tabcontrolAboutWindow.SelectTab(tabcontrolAboutWindow.SelectedIndex - 1)
                End If
            Else
                ' If scrolling up, go right.
                If tabcontrolAboutWindow.SelectedIndex + 1 > tabcontrolAboutWindow.TabCount - 1 Then
                    ' If the next tab is out of bounds above the usable tab indexes,
                    ' select the first tab.
                    tabcontrolAboutWindow.SelectTab(0)
                Else
                    ' Otherwise, select the next tab to the right.
                    tabcontrolAboutWindow.SelectTab(tabcontrolAboutWindow.SelectedIndex + 1)
                End If
            End If
        End If
    End Sub
@DrewNaylor
Copy link
Owner Author

libscrollswitchtabs from the drews-libs project can be used to make things more compact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant