1

I'm developing a windows application that is image viewer. This program contain main form to load picture and another form to load swf file into it dynamically .
work of my application is like this : when mouse clicked on pictureBox on main form an object will be created (type of second form) and should locate in correct position.

I have problem to get correct position. How could do this ?
Thanks for your help

4

1 回答 1

2

窗体上子控件的位置以子坐标给出。换句话说,在相对于父窗体的坐标中。

表单的位置以屏幕坐标给出,因为它们的父级是整个屏幕。

这在文档中针对Location属性的不同重载进行了说明。

Control.Location:获取或设置控件左上角相对于其容器左上角的坐标。

Form.Location:获取或设置代表窗体左上角屏幕坐标的Point。

所以你需要将Form A上PictureBox的位置从子坐标转换为屏幕坐标,然后你可以使用这些屏幕坐标来设置Form B的位置。

要在 WinForms 中执行此操作,请调用以下Control.PointToScreen方法:

Point childCoords  = myPictureBox.Location;
Point screenCoords = myPictureBox.PointToScreen(childCoords);

myOtherForm.Location = screenCoords;
于 2013-04-24T06:06:05.253 回答