Need To Know How To Find Coordinates Of Form
I'm using the GetCursorPos API Call To Get The Cursor POS And Deposit It Into CsrCoords Which Is A PointAPI Type.
I Want To Determine Whether The Cursor Is In The Form, If It Goes Out Of The Form Or On The TitleBar I Want To Call HideLinedControls Which Is A Sub In frmMain.
The Code I Have In The Timer Form Is:
Private Sub MNUTmr_Timer()
If CsrCoords.Y < frmMain.Top Or CsrCoords.Y > frmMain.Top + frmMain.Height Then
Debug.Print "Too High Or Low"
frmMain.HideLinedControls
MNUTmr.Enabled = False
End If
If CsrCoords.X < frmMain.Left Or CsrCoords.X > frmMain.Left + frmMain.Width Then
frmMain.HideLinedControls
Debug.Print "Too Much To Side!"
MNUTmr.Enabled = False
End If
End Sub
HideLinedControls Is A Sub I'm Using To Hide The Lines Of A Control I Made.
How Can I Find Out The Coordinates Of The Form And Use Them In The Above Timer Code To See Whether The Mouse Is OutSide Of The Form Or In The TitleBar?
Re: Need To Know How To Find Coordinates Of Form
just an idea: I think the Top and height properties are in Twips by default.
I think you should transform those to pixels using screen.TwipsPerPixelx and so on.
(BTW: capitalizing the first letter of each word makes your post very hard to read)
Re: Need To Know How To Find Coordinates Of Form
well, i tried setting the scalemode to twips but it would not work. How would i use the Screen.TwipsPerPixelX to determine the top of the form?
Re: Need To Know How To Find Coordinates Of Form
Ok, I haven't tried this, but I'd code like this:
dim lTop as long
ltop = frm.Top * screen.TwipsPerPixelY
lTop whould now contain the Top coordinate in Pixels, right? Now you should compare that with the result from GetCursorPos.
Re: Need To Know How To Find Coordinates Of Form
Thank you man, it worked... i used the following code to determine whether the mouse has gone over the Titllebar or off the form:
Dim MainTop, MainLeft, MainRight, MainBottom As Integer
Private Sub MNUTmr_Timer()
MainTop = (frmMain.Top / Screen.TwipsPerPixelY) + 29
MainLeft = frmMain.Left / Screen.TwipsPerPixelX
MainRight = MainLeft + (frmMain.Width / Screen.TwipsPerPixelX)
MainBottom = MainTop + (frmMain.Height / Screen.TwipsPerPixelY)
If CsrCoords.Y < MainTop Or CsrCoords.Y > MainBottom Then
Debug.Print "Too High Or Low"
frmMain.HideLinedControls
MNUTmr.Enabled = False
End If
If CsrCoords.X < MainLeft Or CsrCoords.X > MainRight Then
frmMain.HideLinedControls
Debug.Print "Too Much To Side!"
MNUTmr.Enabled = False
End If
End Sub
Re: Need To Know How To Find Coordinates Of Form
Thanks for sharing the final code with us.
Re: Need To Know How To Find Coordinates Of Form
I wonder where the +29 in
"MainTop = (frmMain.Top / Screen.TwipsPerPixelY) + 29"
comes from?
Is that because of the border width?
if so, you can probably get the true value from GetSystemMetrics API SM_CYBORDER...