Solved

Click events with right mouse button

Posted on 1998-10-08
6
167 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
[X]
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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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