|
-
Aug 18th, 2006, 12:07 AM
#1
Thread Starter
PowerPoster
[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.
-
Aug 18th, 2006, 12:37 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 18th, 2006, 12:44 AM
#3
Re: show a modal form in a specific location on the screen
VB Code:
Load Form2
Form2.StartUpPosition = 0
Form2.Move Text1.Left, Text1.Top, Text1.Width, Text1.Height
Form2.Show vbModal
-
Aug 18th, 2006, 08:05 AM
#4
Thread Starter
PowerPoster
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.
-
Aug 18th, 2006, 08:06 AM
#5
Re: show a modal form in a specific location on the screen
-
Aug 18th, 2006, 08:09 AM
#6
Re: show a modal form in a specific location on the screen
-
Aug 18th, 2006, 08:16 AM
#7
Hyperactive Member
Re: show a modal form in a specific location on the screen
VB Code:
Public Type POINTAPI
x As Long
y As Long
End Type
Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Sub Text1_Click()
Dim lpPoint As POINTAPI
Call ClientToScreen(Me.Text1.hwnd, lpPoint)
Form2.move lpPoint.X * Screen.TwipsPerPixelX, lpPoint.y * Screen.TwipsPerPixelY
Form2.Show vbModal
End Sub
-
Aug 18th, 2006, 08:23 AM
#8
Thread Starter
PowerPoster
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.
-
Aug 18th, 2006, 08:24 AM
#9
Re: show a modal form in a specific location on the screen
 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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|