Discussion Locked

Acc97 - Open a form in specific position

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I want to open a floating form in a certain position on the screen. The position will be relevant to the coordinates of the mouse-click (which I have already attained).

Any help?

4 replies

by kees.valkenswaard

For me it is not quite clear where you are up to. Perhaps the MoveSize method for the active screen might help you. The form should already be the active screen which can be placed at the desired position. Make certain your X and Y values are in twips.
By the way, how do you get your mouse coordinates?
Good luck

by timfox

Thanks.
I've used the MoveSize method and the cmdObject.Left (and .top) properties of a button that I'm clicking to relocate the form that I'm openning and am thus not using the position of the mouse click. I couldn't (haven't yet) figured out how to convert the x and y to twips!

Incidently, the mouse click position can be found using:
-- Paste into module
Option Explicit
Type POINTAPI 'Declare types
x As Long
y As Long
End Type
Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long 'Declare API

---Use this in your form
Option Explicit
Dim mousePos As POINTAPI 'Declare variable

Private Sub WheresTheMouse()
GetCursorPos mousePos
msgbox "X: " & mousePos.x & ", Y: " & mousePos.y,,"MousePos"
End Sub

by timfox

Just in case you're still watching this one, Kees...

The mouse_up event gives you the mouse pos in twips, but I still can't move the current form in runtime properly. The form moves fine in debug, but not runtime, so I'm going to open another question.

This discussion is closed to new replies.