怎么得到当前控件的绝对位置。
因为有些控件嵌套在如frame或picturebox控件内,他的left,top属性就是相对位置,如何得到他们的绝对位置呢?相对于桌面或窗体。

解决方案 »

  1.   

    对于有窗口的控件,可以用GetWindowRect
    Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
      

  2.   

    Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Public Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    可以用这个api来得到。(数值的单位是:pixel)
    在vb中的数值的单位是:Twips
    需要用Screen.TwipsPerPixelX和Screen.TwipsPerPixelY来做转换。
    1 pixel=about 15 twips