Scrolling on the Middle Mouse Button
Create IE Style scrolling effects
Provides a class that allows you to perform auto-scrolling from the middle Mouse button just like in IE.
Mouse wheels are great. Even better if you're in an idle frame of mind is the click-and-drag-to-scroll you can do when you hit the middle mouse button in an IE Window. So what about adding it to your app's super grid control so your users can have the same sort of fun whilst they're clinching that crucial trade on the phone (or, more likely, waiting until their call "that is important to us" reaches the head of the queue)?
Unfortunately, unlike the mouse wheel messages added to Windows, there is no built-in Windows behaviour for scrolling a viewport on response to the middle mouse button. But that doesn't stop you from building this functionality, provided you can implement a Windows Mouse Hook.
Let's look at the what the drag-middle scrolling does.
Given these specifications, we can implement a version of the same behaviour. The first thing to note is that the last criteria forces use of a MouseHook, because otherwise there is no way of detecting the mouse event which ends the scroll operation.
The code provided with this class consists of three parts:
Once you have these things in your project, middle scrolling can be added to any control that has a hWnd and uses Windows API ScrollBars. For example, to add middle-scrolling to a multi-line text box with both scroll bars visible you would use this code:
' Middle scroller Private m_cMiddleScroller As cMiddleButtonScroller Private Sub Form_Load() ' Create the middle button scroller Set m_cMiddleScroller = New cMiddleButtonScroller End Sub Private Sub txtSample_MouseDown( _ Button As Integer, Shift As Integer, _ X As Single, Y As Single _ ) If (Button = vbMiddleButton) Then With m_cMiddleScroller .HorizontalMode = ePixelBased .VerticalMode = eLineBased .StartMiddleScroll txtSample.hwnd End With End If End Sub
The HorizontalMode and VerticalMode settings of the class allow you to configure the behaviour of the scroller. These can be set one of the following three settings:
This sample demonstrates how to add drag-scrolling in response to a middle mouse button press which emulates the functionality provided in Internet Explorer and Office applications. This is hardly a critical piece of functionality but it can add to the user's experience for large grids or pictures.