Results 1 to 5 of 5

Thread: getting the distance from the top left point and the lower left point of a rectange?

  1. #1

    Thread Starter
    Hyperactive Member dflw's Avatar
    Join Date
    Apr 2001
    Location
    ct, usa
    Posts
    412

    getting the distance from the top left point and the lower left point of a rectange?

    Hello,

    How do i get the distance in pixels between the top left point and lower left point of a rectangle? What are all 4 points on a rectangle named? 0,0 1,1 or something?

    Thanks for any help!
    Visual Basic 6, HTML, JavaScript, learning C++

  2. #2
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    To get the distance from top to bottom and left to right is very simple:

    Distance from top to bottom = rectangle's height
    Distance from left to right = rectangle's width

    I don't quite follow your other question.

  3. #3
    Addicted Member hypnos's Avatar
    Join Date
    Aug 2000
    Location
    UK
    Posts
    183
    BTW, if you wanted to get the distance from the top left vertex to the bottom right vertex of a rectangle, I think you would have to use Pythagoras' theory.

  4. #4
    Zaei
    Guest
    Use the Distance equation:
    Code:
    dist = sqrt(((x2-x1)^2) + ((y2-y1)^2))
    Z.

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    if the rectangle you mention is a form, then you can use the [color]GetClientrect[/color] API function call.

    VB Code:
    1. Option Explicit
    2. '// WIN32API Function
    3. Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    4.  
    5. '// WIN32API Structure
    6. Private Type RECT
    7.         Left As Long
    8.         Top As Long
    9.         Right As Long
    10.         Bottom As Long
    11. End Type
    12.  
    13. Private Sub Command1_Click()
    14.     Dim rc As RECT
    15.     GetClientRect Me.hwnd, rc
    16.     Debug.Print "(" & rc.Left & ", " & rc.Top & ") (" & rc.Right & "," & rc.Bottom & ")"
    17. End Sub
    regards,

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