pnizzle pnizzle - 4 years ago 209
Vb.net Question

VB.net get location of userControl in another container

enter image description here

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 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. These function names are not helping either. I am new to VB.net..

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download