PopupMenu wants the X and Y coordinates in the ScaleMode of the form on which the menu is called. In this case, this probably means a user control.
But it really depends on where you are working with the MouseDown event. (You do not receive coordinates with the Click event.) If your event handler is in the user control itself, then you should not have problems using the supplied coordinates. However, the code you posted doesn't have the Flags parameter (should be vbPopupMenuLeftAlign), which might explain why your coordinate math doesn't work. In addition, you must define the menu as a property of the user control itself.
On the other hand, if you trigger the MouseDown event from a user control and process it in the contained form, the pop-up menu should be a property of the contained form. In this case, you can ignore the X and Y parameters, but you must do the coordination calculations yourself. The left edge of the button relative to the main form will be the sum of the left edge of the userโs control and the offset of the button inside the control. Similar math will work to calculate the bottom edge of the button. In other words:
Private Sub UserControl1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) PopupMenu mnuPopup, vbPopupMenuLeftAlign, _ UserControl1.Left + UserControl1.Button.Left, _ UserControl1.Top + UserControl1.Button.Top + UserControl1.Button.Height End Sub
Note that this will require that you also open the (Button) as a property of the user control so that you can access its Left, Top, and Height properties. This is easy enough:
Public Property Get Button() As CommandButton Set Button = Command1 End Property
Raising an event is quite simple; just put
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
at the top of the user control, then use this:
RaiseEvent MouseDown(Button, Shift, X, Y)
in the MouseDown event of a button in a user control.
Finally, to attach an event handler in the main form, use the two drop-down lists at the top of the code editing window. Select a user control from the list on the left, then select the MouseDown event from the list on the right. This inserts an event handler that you populate with the code above.
How much better, processing the menu inside the user control itself and raising significant events when choosing one of them separates things. The user control processes the user interface, leaving the main application to process everything that needs to be done in response to the user's choice, without worrying about the layout of the menu.
This way you will not actually raise a MouseDown event; rather, you will raise events like OptionOneSelected, OptionTwoSelected, or OptionThreeSelected. (Of course, more meaningful names would be much better.)
In any case, I hope it is not too late to be of service ...