Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 274165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:34:06+00:00 2026-05-12T00:34:06+00:00

I have a VB6 app. There is a main form. It houses a user

  • 0

I have a VB6 app. There is a main form. It houses a user control. This user control has a button control. When I click the button, I want a menu to pop up so that the top left of the menu is right underneath the bottom left of the button.

if I do:

frm.PopupMenu mnuBlah

the menu comes up where the mouse is.

if I try to provide coordinates

frm.PopupMenu mnuBlah, btn.Left, btn.Top + btn.Height

the math comes out totally wrong and the menu is displayed way off target.

I am not quite sure what type of coordinates the PopupMenu call requires and how to calculate the position underneath the button.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:34:07+00:00Added an answer on May 12, 2026 at 12:34 am

    PopupMenu wants X and Y coordinates in the ScaleMode of the form on which the menu is being popped up. In this case, that probably means the user control.

    But it really depends on where you’re handling the MouseDown event. (You don’t get coordinates with the Click event.) If your event handler is in the user control itself, then you shouldn’t have any problem using the supplied coordinates. However, the code you posted is missing the Flags parameter (should be vbPopupMenuLeftAlign), which could explain why your coordinate math isn’t working. Plus, you have to define the menu as a property of the user control itself.

    On the other hand, if you raise the MouseDown event out of the user control, and handle it in the containing form, the popup menu has to be a property of the containing form. In this case, you can ignore the X and Y parameters, but you have to do coordinate calculations yourself. The left edge of the button, relative to the main form, will be the sum of user control’s left edge and the offset of the button within 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 expose the button (Button) as a property of the user control so that you can access its Left, Top, and Height properties. That’s easy enough:

    Public Property Get Button() As CommandButton
        Set Button = Command1
    End Property
    

    Raising the event is simple enough as well; 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 the button in the user control.

    Finally, to wire up the event handler in the main form, use the two dropdowns at the top of the code editing window. Select the user control from the one on the left, then select the MouseDown event from the one on the right. This will insert the event handler, which you fill in with the code above.

    As far as which way is better, handling the menu inside the user control itself, and raising meaningful events when one is selected keeps things separated. The user control handles the UI work, leaving the main application to handle whatever needs to be done in response to the user’s selection, without worrying about placement of the menu.

    So you wouldn’t actually be raising the MouseDown event; rather you’d raise events like OptionOneSelected, OptionTwoSelected, or OptionThreeSelected. (More meaningful names would be much better, of course.)

    Anyway, I hope this isn’t too late to be helpful…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 231k
  • Answers 231k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use the following function like this: Image('/path/to/original.image', '1/1', '150*', './thumb.jpg');… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer Check you database schema to see if the field (referenced… May 13, 2026 at 2:13 am
  • Editorial Team
    Editorial Team added an answer I figured out the problem - there was a session… May 13, 2026 at 2:13 am

Related Questions

I was reading about the Form's events in VB6 such as Unload QueryUnload and
We have an unattended app w/o a user interface that is is periodically run.
My application is a vb6 executable, but some newer forms in the system are
I have a VB6 app that formerly worked perfectly on a Vista machine as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.