CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2001
    Location
    St. Petersburg, FL
    Posts
    10

    DblClick/Click Mouse Events

    I have a picture box and I want to execute one event if the right mouse button is pressed ( I am using the MouseUP where Button=2) and another event if I doubleclick or left mouse button click.

    For some reason the MouseUP Button=2 event works fine, but the Dblclick event or the Click or MouseDown click doesn't fire when used in my same form module.
    I've heard about an order of precedence on mouse events. MouseDn comes first, then MouseUp, then Click, then Doubleclick. Does this mean that if I have a Mouseup event for a picture box that I cannot assign a Doubleclick to that same picture box?

    To test the events...
    I created a new project and created one simple picture box and applied the Click and DblClick event to it. The event only worked if I 'Right' clicked or 'Right' Doubleclicked. Why would that be?

    My mouse operates properly but something must be changing the features of my mouse during Run time.

    Thanks.

    Wendell W. Wilson
    Software Engineer
    St. Petersburg, FL

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: DblClick/Click Mouse Events

    If you have a MouseClick event, the DblClick event will never fire... you can still use MouseDown and MouseUp however.


  3. #3
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: DblClick/Click Mouse Events

    It seems to me that your mouse button settings were changed to Left-handed. When you click, the order of events will be: MouseDown then MouseUp then Click. On double click the order is: MouseDown then MouseUp then Click then DblClick. In both cases the MouseDown,MouseUp and Click events will fire.



  4. #4
    Join Date
    Aug 2001
    Location
    St. Petersburg, FL
    Posts
    10

    Re: DblClick/Click Mouse Events

    Thanks. But then how do I have a Picture box take on a certain event for a left button MouseDn event and have the same Picture box take on a different event for a right button MouseDn event?
    The following code works for a right mouse click, but not for a left click. I thought the values for Button can be 0, 1, or 2.

    private Sub Picture1_MouseDown(Index as Integer, Button as Integer, Shift as Integer, X as Single, Y as Single)
    If Button = 2 then
    Debug.print "Right Mouse Button was Pressed!"
    else
    Debug.print "Another Button was Pushed!!"; Button
    End If

    End Sub




    Thanks.

    Wendell W. Wilson
    Software Engineer
    St. Petersburg, FL

  5. #5
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: DblClick/Click Mouse Events

    With the following code I get:
    1 Left (on a left-click)
    2 Right (on a right-click)
    4 Other (on a wheel-click)

    private Sub Picture1_MouseDown(Button as Integer, Shift as Integer, X as Single, Y as Single)
    Select Case Button
    Case vbRightButton
    MsgBox Button & " Right"
    Case vbLeftButton
    MsgBox Button & " Left"
    Case else
    MsgBox Button & " Other"
    End Select

    End Sub





  6. #6
    Join Date
    Aug 2001
    Location
    St. Petersburg, FL
    Posts
    10

    Re: DblClick/Click Mouse Events

    Thanks. I did check my mouse settings. They're ok. My mouse works fine.
    The MouseDown event fires for my Picture Box, but only if the right mouse button is pressed. I want to use MouseDown for the left mouse button.
    When I use an 'if button = 1' condition, for the left mouse button, I never get a response. i.e. the left button doesn't register.
    Any suggestions?

    Wendell W. Wilson
    Software Engineer
    St. Petersburg, FL

  7. #7
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: DblClick/Click Mouse Events

    I read again your previous posting and you mention that when you right click Button=2, that corresponds to a right button. By the way the sequence of events is the same for right and left clicking. To differentiate between them you check the Button value in any of these events.
    Did you try to trace the Click event with other controls like a textbox?



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

Featured