Results 1 to 9 of 9

Thread: [RESOLVED] show a modal form in a specific location on the screen

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Resolved [RESOLVED] show a modal form in a specific location on the screen

    Hello,
    How would I do the following: display a small modal form at roughly the same position as where the user clicks on the current form - for example, when the user clicks on a textbox on Form1, display a small modal Form2 in roughly the same spot as the textbox on Form1.
    Thanks.
    Last edited by BruceG; Aug 18th, 2006 at 08:23 AM.
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: show a modal form in a specific location on the screen

    Check out Aaron Youngs code for positioning a MsgBox before its shown.

    http://vbforums.com/showthread.php?t=329373
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: show a modal form in a specific location on the screen

    VB Code:
    1. Load Form2
    2.     Form2.StartUpPosition = 0
    3.     Form2.Move Text1.Left, Text1.Top, Text1.Width, Text1.Height
    4.         Form2.Show vbModal

  4. #4

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: show a modal form in a specific location on the screen

    Thanks, guys, but I've got issues:

    RobDog- I did not see anywhere in those posts code to actually position the Msgbox (maybe I missed it)

    gavio - the problem with using left, top, etc. is that the textbox on form1 could be in a frame which is in an SStab, which is in an MDI form, all of which throw off the positioning.

    What I am looking for is a way to determine the "absolute screen position" of the mousepointer (as when the user clicks on the textbox), and then use that information to position the modal form on the screen.

    Thanks again.
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: show a modal form in a specific location on the screen

    use the GetCursorPos API

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: show a modal form in a specific location on the screen

    See Joacim's post here

  7. #7
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: show a modal form in a specific location on the screen

    VB Code:
    1. Public Type POINTAPI
    2.  
    3.        x As Long
    4.        y As Long
    5.  
    6. End Type
    7.  
    8. Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    9.  
    10. Private Sub Text1_Click()
    11.  
    12.   Dim lpPoint As POINTAPI
    13.  
    14.   Call ClientToScreen(Me.Text1.hwnd, lpPoint)
    15.  
    16.   Form2.move lpPoint.X * Screen.TwipsPerPixelX, lpPoint.y * Screen.TwipsPerPixelY
    17.   Form2.Show vbModal
    18.  
    19. End Sub

  8. #8

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: show a modal form in a specific location on the screen

    Sweet - thanks guys (Jocaim's code in Hack's link (using the GetCursorPos API) did the trick).
    tward_biteme1 - looks like the ClientToScreen API would also work as well.

    Much appreciated.
    "It's cold gin time again ..."

    Check out my website here.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: show a modal form in a specific location on the screen

    Quote Originally Posted by BruceG
    Thanks, guys, but I've got issues:

    RobDog- I did not see anywhere in those posts code to actually position the Msgbox (maybe I missed it)

    gavio - the problem with using left, top, etc. is that the textbox on form1 could be in a frame which is in an SStab, which is in an MDI form, all of which throw off the positioning.

    What I am looking for is a way to determine the "absolute screen position" of the mousepointer (as when the user clicks on the textbox), and then use that information to position the modal form on the screen.

    Thanks again.
    Look at post 6 and 7 and specifically the MsgBoxEx function is receiving the coords and applying them in the SubMsgBox function with GetWindowRect and MoveWindow.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width