Find actual coordinates of a control within another control 
Author Message
 Find actual coordinates of a control within another control

Hi,

How can we find the coordinates to to upper left corner of a control if that
control is put in another control, for example picture or frame. It can be
multiple levels.

I want to find the top and left coordinates I can use to open a new form at
the spot where the control who was clicked is. So it should return x and y
from the parent window perspective.

Comprende ?

David



Sat, 11 Dec 2010 23:43:52 GMT  
 Find actual coordinates of a control within another control

released on Tue, 24 Jun 2008 17:43:52 +0200 bearing the
following fruit:

Quote:
>Hi,

>How can we find the coordinates to to upper left corner of a control if that
>control is put in another control, for example picture or frame. It can be
>multiple levels.

>I want to find the top and left coordinates I can use to open a new form at
>the spot where the control who was clicked is. So it should return x and y
>from the parent window perspective.

>Comprende ?

Not really, it sounds like you want the screen coordinates.

Take a look at the clienttoscreen API

--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde



Sun, 12 Dec 2010 00:27:13 GMT  
 Find actual coordinates of a control within another control


Quote:
> How can we find the coordinates to to upper left corner of a control if that
> control is put in another control, for example picture or frame. It can be
> multiple levels.

You'll have to calculate its position from a container that has a windows
handle. (hWnd property).  Paste the code below into a new form and
see if this gets you farther along....
(Click on the form to show another one)

LFS

Option Explicit
Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Declare Function ClientToScreen Lib "user32" _
        (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Sub Form_Load()
  ' API expects pixels
  Me.ScaleMode = vbPixels
  ' Screen uses Twips
  Me.Move Me.Left, Me.Top, 4000, 3000
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pt As POINTAPI
  ' Location of mouse (your control...)
  pt.X = X
  pt.Y = Y
  ' Translate to screen location
  If ClientToScreen(Me.hwnd, pt) Then
    Dim frm As New Form1
    ' Convert pixels to twips
    frm.Move ScaleX(pt.X, vbPixels, vbTwips), ScaleY(pt.Y, vbPixels, vbTwips)
    frm.Show
  End If
End Sub



Sun, 12 Dec 2010 01:22:16 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. how to find which control/window cursor is over with just coordinates

2. keeping track of actual y-coordinate in a report

3. Finding controls / COM objects within an OCX/DLL file

4. How do I coordinate the screen's coordinates with a form coordinate

5. Help: Referencing controls within a tab-control

6. Filter for actual work within specific date range

7. How can I directly access properties/methods of a control within my ActiveX control

8. help: Control within Control

9. Printing a picture control and child controls within

10. Using Script from within ActiveX Control (scripting control???)

11. How can I directly access properties/methods of a control within my ActiveX control

12. ActiveX control within ActiveX control Licencing Error 429

 

 
Powered by phpBB® Forum Software