Solved

Click events with right mouse button

Posted on 1998-10-08
6
161 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 80
VB error "Type mismatch" 2 43
Windows 10 start screen issues 9 47
Updates not working for MS Windows 7 12 124
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now