Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Click events with right mouse button

Posted on 1998-10-08
6
165 Views
Last Modified: 2010-05-18
if you click on a label it executes the label1_Click code, but I  then need to procede differently according to whether the click was with a left or right mouse button

Is this possible.  I know other events such as the mousedown event has a Button parameter which the click event does not - do this mean it is not possible?  If so are there any other ways  of doing the same thing - I dont want to use the mouse down event instead as I may need this for dragging and  dropping.

0
Comment
Question by:Taranadilla
6 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1438817
I don't think there's a way to go with click event.  You have to use MouseUp event - and further check whether the mouse is within your control (if not, do not do "click" subroutine).
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1438818
Taranadilla,
In the mousedown event, you have a Button parameter.
If 0, it is the left,
1 is the right and 2 is the middle.
Regards
Dalin
0
 

Author Comment

by:Taranadilla
ID: 1438819
I know about the Button parameter in the mouse down event but as I said I am reluctant to use this event because it will preclude the use of drag and drop later.  What I am after is a way of coding the click event so that it knows about left and right mouse buttons, or an alternative way of doing the same thing.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:Dalin
ID: 1438820
Sorry, I missed the last part of the your question...I don't know how, but I just did not see the 2nd part. May be I need to get some coffee. it was 7:30 in the morning.

I am not aware of any other way that is easier than use the mousedown.  You can change the click from left to right, but I believe once it's set,  it takes it for granted.

Again, Sorry for the mistake.
0
 
LVL 1

Accepted Solution

by:
gissing earned 200 total points
ID: 1438821
The way I like to do it is to have two integer module-level variables in your form (ie in the declarations section):

Private m_iButton As Integer
Private m_iShift As Integer

In the Mouse_Down event of the control whose click event you're dealing with, just set them:

Private Sub YourControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

m_iButton = Button
m_iShift = Shift

End Sub

Then in the click event, you can do:

Private Sub YourControl_Click ()

If m_iButton = vbRightButton Then ...

End Sub


This is the only way to achieve what you want without resorting to the API. And even if you do use API calls, don't forget that by the time VB generates the click event, the mouse button has already been released.


0
 

Author Comment

by:Taranadilla
ID: 1438822
Problem solved completely - Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question