VB.net获取userControl在另一个容器中的位置 [英] VB.net get location of userControl in another container

查看:122
本文介绍了VB.net获取userControl在另一个容器中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在引用上图时:在VB.net中,我有四个Windows.Forms.UserControl实例. A,B,C和D.如您所见,B在A中,C在B中,D在C中.D引用了A,并希望计算其在A中的位置.类似我的东西.getLocationInContainer(A),其中我指的是D.如何执行此操作?我做了一些研究,发现了pointToScreen()和pointToClient(),但无法真正弄清楚如何使用它们.函数名称也无济于事.我是VB.net的新手..

While referring to the above image: in VB.net,I have four instances of Windows.Forms.UserControl. A,B,C, and D. As you can see, B is in A, C is in B, and D is in C. D has a reference to A, and would like to calculate its location in A. Something like Me.getLocationInContainer(A) where Me is referring to D. How can I do this? I have done a bit of research and found pointToScreen() and pointToClient() but can't really figure out how to make use of them. The function names are not helping either. I am new to VB.net..

推荐答案

D有一个对A的引用...我指的是D ...我做了一些研究后发现 pointToScreen()和pointToClient()但无法真正弄清楚如何 利用它们.

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的引用将其转换回客户坐标.那就是你的答案:

That would certainly be the easiest route. Start by having D convert the point (0, 0) to screen coords. Then use the reference to A to get it converted back to client coords. That'll be your answer:

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

这篇关于VB.net获取userControl在另一个容器中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆