Re: Tab Control Scrolling
Quote:
Originally Posted by
TechMe.NET
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
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
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