CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 1999
    Location
    Michigan
    Posts
    3

    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?


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    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)


  3. #3
    Join Date
    Aug 1999
    Location
    Michigan
    Posts
    3

    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?


  4. #4
    Join Date
    May 1999
    Posts
    3,332

    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.


  5. #5
    Join Date
    Aug 1999
    Location
    Michigan
    Posts
    3

    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


  6. #6
    Join Date
    May 1999
    Posts
    3,332

    Re: Need To Know How To Find Coordinates Of Form

    Thanks for sharing the final code with us.


  7. #7
    Join Date
    May 1999
    Posts
    3,332

    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...


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

Featured