[2005] Mouse wheel button scroll
Does any one know how I can enable the user to scroll a ListView control using the mouse wheel button (ie you press the mouse wheel and you can then scroll left, right or up and down by gesturing with the mouse like in Internet Explorer)? Thanks in advance!
Re: [2005] Mouse wheel button scroll
About a year ago, I struggled with this for a while in VS 2003, and I couldn't get anywhere. If I remember correctly, the documentation said that VB accessing the mouse wheel was not supported
Re: [2005] Mouse wheel button scroll
You can access the mouse button in VB 2005 as the MiddleButton.
Re: [2005] Mouse wheel button scroll
Does anyone have any ideas?
Re: [2005] Mouse wheel button scroll
i dont know about .Net, but BushMobile made a similar application, using scroll button in any control, in VB6. search for it here.
maybe BM have it in his sig!!
1 Attachment(s)
Re: [2005] Mouse wheel button scroll
Thanks for your response, Harsh Gupta. The effect I'm trying to emulate is the same as when you press the scroll wheel button in Internet Exporer and you get the following cursor:
http://www.vbforums.com/attachment.p...id=49775&stc=1
The page is then scrolled in the a particular direction and speed depending on the location of the mouse pointer from its position when you press the wheel button.
Re: [2005] Mouse wheel button scroll
Quote:
Originally Posted by dom_stapleton
Does any one know how I can enable the user to scroll a ListView control using the mouse wheel button (ie you press the mouse wheel and you can then scroll left, right or up and down by gesturing with the mouse like in Internet Explorer)? Thanks in advance!
Hi,
A little late for answering but it could be the solution how to use the mousewheel.
Here's a link about that;
http://msdn.microsoft.com/library/de...deltatopic.asp
Hope it helps,
sparrow1
Re: [2005] Mouse wheel button scroll
Thanks for your response, sparrow1, but the effect I am trying to achieve only uses the mouse wheel to initiate the event.
What happens is the user can press the mouse wheel button (I know how to catch this), the mouse pointer then turns into the cursor shown in post #6. Then what happens is the user can navigate/scroll through the list view in the direction the user moves the mouse in relation to the postion where the user pressed the mouse wheel buton. It's incredibly hard to describe, it's best if you try it your self. If you have a mouse wheel button, position the pointer in the middle of your browser window and push it and you'll see what I mean.
Re: [2005] Mouse wheel button scroll
Here is what you are after. Note that you are going to have to figure out how to get the actual cursor you want....But that shouldn't be to difficult.
VB Code:
Private m_ScrollClicked As Boolean = False ' if the scroll wheel is down this is set to true
Private m_StartLocation As Point ' this is the cursor position relative to the form when the scroll wheel is clicked
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Middle Then
m_ScrollClicked = True ' the scroll wheel has been clicked
m_StartLocation = Windows.Forms.Cursor.Position 'set the position of where the scroll wheel was clicked
Windows.Forms.Cursor.Current = Cursors.HSplit 'change the cursor
Timer1.Start() 'star the timer
End If
End Sub
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
If m_ScrollClicked = True Then 'the cursor kept changing back to the default
Windows.Forms.Cursor.Current = Cursors.HSplit 'so reset it to your cursor when the mouse moves and the scroll is down
End If
End Sub
Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
m_ScrollClicked = False 'when a mouse button goes up, I assume it is the middle
Windows.Forms.Cursor.Current = Cursors.Default 'change the cusor back to default
Timer1.Stop() 'stop the timer
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'The timer is what actually moves the listview. If the current y is less than the clicked you move up
'if the current y is greater than the clicked y you move down
Dim i As Integer = ListView1.Items.IndexOf(ListView1.TopItem) 'gets the index of the first item that can be seen
If m_ScrollClicked = True AndAlso Windows.Forms.Cursor.Position.Y < m_StartLocation.Y Then
If i > 0 Then 'if there is an item above it, change the top item to that
ListView1.TopItem = ListView1.Items.Item(i - 1)
End If
ElseIf m_ScrollClicked = True AndAlso Windows.Forms.Cursor.Position.Y > m_StartLocation.Y Then
If i < ListView1.Items.Count - 1 Then 'if there is an item below it, change the item to that
ListView1.TopItem = ListView1.Items.Item(i + 1)
End If
End If
End Sub
I had the timer set to 500 milliseconds, but you will want to play around with that until you get it moving how you want it to move. Also you can use this code to increase the speed as it gets farther away from the click point, by comming up with a formula to decrease the timer interval as it gets farther away, or by increasing the number of items it moves up or down during after each interval.