Add-in自定义工具,想在鼠标点击地图位置处弹出form窗体,但窗体弹出位置不对

Add-in自定义工具,想在鼠标点击地图时,在该鼠标处弹出自定义form窗体,但是弹出窗体的位置不对,不是在鼠标点击的地方弹出来的
已邀请:

朱新颖

赞同来自:

【解决办法】:
Add-in中自定义Tool的OnMouseDown事件参数MouseEventArgs arg,arg.Location是以ArcMap中地图区域的左上角为0,0的屏幕坐标,而form.Location是以整个计算机屏幕左上角为0,0的坐标,所以需要进行换算。
1,获取arg.Location;
2,通过 GetWindowRect(int hWnd, ref rect lpRect);获取当前IActiveView相对于计算机屏幕的位置和大小;
3,原始点X坐标+lpRect.Left,原始Y坐标+lpRect.Top 即为该点相对于计算机屏幕的坐标,也就是Form窗体弹出的坐标。



IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;
IActiveView actieview = mxDocument. ActiveView;
Point point = arg.Location;

rect lpRect = new rect();
GetWindowRect(actieview.ScreenDisplay.hWnd, ref lpRect);

Form1 form1 = new Form1();
form1.StartPosition = FormStartPosition.Manual;
Point points = new Point();
points.X = point.X + lpRect.Left;
points.Y = point.Y + lpRect.Top;
form1.Location = points;
form1.Show();


要回复问题请先登录注册