[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.
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
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
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.
Re: show a modal form in a specific location on the screen
Re: show a modal form in a specific location on the screen
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
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.
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. ;)