如何获得与其他控件相关的控件位置

时间:2014-12-31 15:59:59

标签: c# .net position picturebox

假设我有两个相互重叠的图片框,如下所示

enter image description here

如何获得图片框2相对于picturebox1的位置?

先谢谢。 :):)

1 个答案:

答案 0 :(得分:0)

转换为屏幕坐标,然后返回到客户端坐标:

        Rectangle PB2Screen = pictureBox2.RectangleToScreen(pictureBox2.ClientRectangle);
        Rectangle PB2RelativeToPB1 = pictureBox1.RectangleToClient(PB2Screen);
        Console.WriteLine("pictureBox2 Location Relative to pictureBox1: " + PB2RelativeToPB1.Location.ToString());
        Console.WriteLine("PB2RelativeToPB1: " + PB2RelativeToPB1.ToString());