MouseDown event constants

djreiswig

Well-known Member
Joined
Mar 13, 2010
Messages
523
Anybody know what the constants are for the mouse buttons for the mousedown event on an activex textbox? According to the help file they should be:

fmButtonLeft
fmButtonRight
fmButtonMiddle

but these all show a value of empty. I tried changing the fm to xl with the same results. I know I can just use 1,2 or 4, but I like using the constants. It makes things easier to read.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Have you tried xlNoButton, xlPrimaryButton and xlSecondaryButton ?

They return 0, 1, and 2 which is consistent with my testing the MouseDown event on a userform control.
 
Upvote 0
I hadn't tried those constants, but I have an activex textbox on a sheet, and when I left click the button value is 1 and when I right click it is 2. I don't know what the middle button is, because my laptop doesn't have one. I guess it isn't a big deal, just strange that the help mentions 3 constants that apparently don't exist.

It also appears that the mousedown event fires twice. When I put code in to show a userform on a right click on the textbox, when I dismiss the form it reappears a second time. After I dismiss it again, it stays unloaded. If I put the code in the mouseup event then it only shows once. Strange.
 
Upvote 0
Sorry, the previous post was in reference to mikerickson.

pgc01, it appears that those are the constants I'm looking for. I wonder why they didn't list those in the help file?

Any ideas on the strange mousedown behavior?
 
Upvote 0
Any ideas on the strange mousedown behavior?

No, but I noticed it.

On workaround is to execute the code only every other time, when the right button is clicked.

Code:
Private Sub TextBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Static bRightClick As Boolean
 
If Button = vbKeyRButton Then
    bRightClick = Not bRightClick
    If bRightClick Then Exit Sub
End If
 
' your code
 
End Sub

Not satisfactory, though. Maybe someone else explains this behaviour.
 
Upvote 0
Good, I'm not the only one. If I put the code in the mouseup it works fine, but it is a little strange for the form to not show up until the button is released.

If you use the BeforeRightClick event on the sheet, the event is fired when the button is pressed down. I would like something similar to happen on the textbox, for a consistent function.

Your workaround should work, but I wonder if that variable could get off and mess things up so you have to click twice to make it work.
 
Upvote 0
Hi

Just as a confirmation, I asked around and other mvp's, VoG, Rorya and Colin Legg, confirmed this odd behaviour of the right-click event firing twice. Also this is a known bug, that affects not only textboxes but also other activeX controls, like comboboxes, etc.

This means that you must use a workaround like the one I posted that only allows the code to execute every other time.
 
Upvote 0

Forum statistics

Threads
1,215,674
Messages
6,126,140
Members
449,294
Latest member
Jitesh_Sharma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top