tags:

views:

59

answers:

1

I use the function PointToScreen to get the screen related point of the control it gives proper value if I use this function for the toolstrip which is top on the form, but if there is menustrip on the top of the form and then under the menustrip, toolstrip is there then the function does not give proper value of screen point for the control toolstrip.

So,when I use this function for the toolstrip which is top on the form right now then it gives proper location like it gives Y position of 26 which is ok.

Now I am adding the menustrip top of the form and toolstrip is now under the menustrip and now if I use the function then it does not give proper value like,it gives y position of 74,which should be (26 + height of menustrip) = 50.

+1  A: 

I would verify that you are calling PointToScreen on the correct control. If you want to find the location of a control in screen coordinates, call PointToScreen on its parent control.

For example:

control.Parent.PointToScreen(control.Location);

If you call PointToScreen on the control itself using a point relative to the parent control (such as Control.Location), you will get the wrong location.

For example:

Lets say control.Location = new Point(0, 20). If the parent is located at (100, 100) relative to the desktop, then the desktop position of the control is (100, 120). If you call PointToScreen on the parent control, then you will get (100, 120). If you call PointToScreen on the control itself, you will get the location of the point (0, 20) relative to the desktop location of the control, which would end up being (100, 140).

Zach Johnson
Thank You Sir. It works...
Harikrishna