VB.net get location of userControl in another container

怎甘沉沦 提交于 2019-12-13 07:24:01

问题


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..


回答1:


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.

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)


来源:https://stackoverflow.com/questions/42079832/vb-net-get-location-of-usercontrol-in-another-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!