VB.net 获取 userControl 在另一个容器中的位置

VB.net get location of userControl in another container

参考上图:在VB.net中,我有四个Windows.Forms.UserControl实例。 A、B、C 和 D。如您所见,B 在 A 中,C 在 B 中,D 在 C 中。D 引用了 A,并想计算它在 A 中的位置。类似 Me.getLocationInContainer(A) 其中我指的是 D。我该怎么做?我做了一些研究并找到了 pointToScreen() 和 pointToClient() 但无法真正弄清楚如何使用它们。函数名称也无济于事。我是 VB.net..

的新手

D has a reference to A ... where Me is referring to D ... I have done a bit of research and found pointToScreen() and pointToClient() but can't really figure out how to make use of them.

那肯定是最简单的路线。首先让 D 将点 (0, 0) 转换为屏幕坐标。然后使用对 A 的引用将其转换回客户端坐标。这就是你的答案:

Dim ucDscreenCoords = Me.PointToScreen(New Point(0, 0))
Dim ucDclientCoordsRelativeToA = A.PointToClient(ucDscreenCoords)