Results 1 to 9 of 9

Thread: [2005] Mouse wheel button scroll

  1. #1

    Thread Starter
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Lightbulb [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!
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  2. #2
    Lively Member bmilano's Avatar
    Join Date
    Jan 2005
    Location
    Broad Run, VA
    Posts
    126

    Unhappy 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
    If you like my posts, please rate them so I can be somebody!

  3. #3

    Thread Starter
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Re: [2005] Mouse wheel button scroll

    You can access the mouse button in VB 2005 as the MiddleButton.
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  4. #4

    Thread Starter
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Re: [2005] Mouse wheel button scroll

    Does anyone have any ideas?
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  5. #5
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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!!
    Show Appreciation. Rate Posts.

  6. #6

    Thread Starter
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    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:



    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.
    Attached Images Attached Images  
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  7. #7
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    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
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  8. #8

    Thread Starter
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    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.
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  9. #9
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    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:
    1. Private m_ScrollClicked As Boolean = False  ' if the scroll wheel is down this is set to true
    2.     Private m_StartLocation As Point            ' this is the cursor position relative to the form when the scroll wheel is clicked
    3.  
    4.  
    5.     Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
    6.         If e.Button = Windows.Forms.MouseButtons.Middle Then
    7.             m_ScrollClicked = True              ' the scroll wheel has been clicked
    8.             m_StartLocation = Windows.Forms.Cursor.Position     'set the position of where the scroll wheel was clicked
    9.             Windows.Forms.Cursor.Current = Cursors.HSplit       'change the cursor
    10.             Timer1.Start()                                      'star the timer
    11.         End If
    12.     End Sub
    13.  
    14.     Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
    15.         If m_ScrollClicked = True Then                      'the cursor kept changing back to the default
    16.             Windows.Forms.Cursor.Current = Cursors.HSplit   'so reset it to your cursor when the mouse moves and the scroll is down
    17.         End If
    18.     End Sub
    19.  
    20.     Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
    21.         m_ScrollClicked = False                             'when a mouse button goes up, I assume it is the middle
    22.         Windows.Forms.Cursor.Current = Cursors.Default      'change the cusor back to default
    23.         Timer1.Stop()                                       'stop the timer
    24.     End Sub
    25.  
    26.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    27.         'The timer is what actually moves the listview.  If the current y is less than the clicked you move up
    28.         'if the current y is greater than the clicked y you move down
    29.         Dim i As Integer = ListView1.Items.IndexOf(ListView1.TopItem) 'gets the index of the first item that can be seen
    30.         If m_ScrollClicked = True AndAlso Windows.Forms.Cursor.Position.Y < m_StartLocation.Y Then
    31.             If i > 0 Then   'if there is an item above it, change the top item to that
    32.                 ListView1.TopItem = ListView1.Items.Item(i - 1)
    33.             End If
    34.         ElseIf m_ScrollClicked = True AndAlso Windows.Forms.Cursor.Position.Y > m_StartLocation.Y Then
    35.             If i < ListView1.Items.Count - 1 Then   'if there is an item below it, change the item to that
    36.                 ListView1.TopItem = ListView1.Items.Item(i + 1)
    37.             End If
    38.         End If
    39.     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.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

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