Popup Form on Cursor or button location

Posted on 2008-11-04
Last Modified: 2012-05-05
I am starting to go in circles looking for the best way to do this, so I want to ask:

I am trying to open a small form from a button click event in a VB.Net 2008 Windows app. The form with the button is a child form within a MDIParent form. The popup form needs to open up  at the position where either my button is or where my cursor is. And lastly, the popup form needs to return a value back to the child form (should this be a dialog or a modal form?).

Please post a code sample so I can follow it. Also, let me know if the popup form should have a specific StartPosition  (like "Manual"). Thanks! I hope I explained this good enough for you to follow. Just ask if I didn't.
Question by:JeepGeekin
    LVL 14

    Accepted Solution


    myPopUpForm.Location = Cursor.Position;

    Place a public member on myPopUpForm and store the value that is for return.

    // get the value after myPopUpForm is closed
    myVar = myPopUpForm.someVar;


    Author Comment

    Thanks for the post, but I tried this. For some reason the widow opens wherever it wants. It does not open at the location we specify. If you want to see my click event code, here it is:

    Private Sub picCustLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picCustLookup.Click
          Dim frmCust As New frmCustomer
          Dim sReturn As String
          frmCust.Location = Cursor.Position
    End Sub

    Open in new window


    Author Comment

    Ah. I had to set the popup window's StartPosition = Manual. That works. I have been going through several combos of this setting & the different popup form types I lost track. Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now