Results 1 to 3 of 3

Thread: Tab Control Scrolling

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    23

    Tab Control Scrolling

    I have a tab control with two tab pages. One page has the auto scroll enabled since there is to much content in the page.

    The middle mouse wheel doesn't scroll the scroll bar; I have to actually click and hold the scroll bar and drag it down to scroll. Is there a property to allow this?

    Thanks,

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Tab Control Scrolling

    Quote Originally Posted by TechMe.NET View Post
    I have a tab control with two tab pages. One page has the auto scroll enabled since there is to much content in the page.

    The middle mouse wheel doesn't scroll the scroll bar; I have to actually click and hold the scroll bar and drag it down to scroll. Is there a property to allow this?

    Thanks,
    I see the TabControl MouseWheel event fires when a tabpage has focus (and controls inside the tabpage do not have focus) when you use the mousewheel, but like you say the scroll bar for the tab control doesn't get effected.

    I'm not sure if there is some setting to make it work that way, I didn't see anything offhand so came up with this real quick,...

    Code:
    Public Class Form1
        <System.Runtime.InteropServices.DllImport("user32.dll")> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
        Private Const WM_VSCROLL As Int32 = &H115
        Private Const SB_LINEUP As Int32 = 0
        Private Const SB_LINEDOWN As Int32 = 1
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            TabControl1.TabPages(0).AutoScroll = True
            TabControl1.TabPages(1).AutoScroll = True
        End Sub
    
        Private Sub TabControl1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseWheel
            If e.Delta > 0 Then
                ' scroll selected tabpage upwards
                SendMessage(TabControl1.TabPages(TabControl1.SelectedIndex).Handle, WM_VSCROLL, SB_LINEUP, 0)
            Else
                'scroll selected tabpage downwards
                SendMessage(TabControl1.TabPages(TabControl1.SelectedIndex).Handle, WM_VSCROLL, SB_LINEDOWN, 0)
            End If
        End Sub
    End Class

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    23

    Resolved Re: Tab Control Scrolling

    I think I found a better solution. It looks like the middle mouse isn't activated until you click a control/item in the tabpage. I was able to set focus on the tabpage with a enter event using this code Me.ActiveControl = Me.TabPage1


    Quote Originally Posted by Edgemeal View Post
    I see the TabControl MouseWheel event fires when a tabpage has focus (and controls inside the tabpage do not have focus) when you use the mousewheel, but like you say the scroll bar for the tab control doesn't get effected.

    I'm not sure if there is some setting to make it work that way, I didn't see anything offhand so came up with this real quick,...

    Code:
    Public Class Form1
        <System.Runtime.InteropServices.DllImport("user32.dll")> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
        Private Const WM_VSCROLL As Int32 = &H115
        Private Const SB_LINEUP As Int32 = 0
        Private Const SB_LINEDOWN As Int32 = 1
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            TabControl1.TabPages(0).AutoScroll = True
            TabControl1.TabPages(1).AutoScroll = True
        End Sub
    
        Private Sub TabControl1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TabControl1.MouseWheel
            If e.Delta > 0 Then
                ' scroll selected tabpage upwards
                SendMessage(TabControl1.TabPages(TabControl1.SelectedIndex).Handle, WM_VSCROLL, SB_LINEUP, 0)
            Else
                'scroll selected tabpage downwards
                SendMessage(TabControl1.TabPages(TabControl1.SelectedIndex).Handle, WM_VSCROLL, SB_LINEDOWN, 0)
            End If
        End Sub
    End Class
    Last edited by TechMe.NET; May 23rd, 2012 at 02:25 PM.

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