ArcGIS Engine 修改 PageLayout 中地图比例尺时出现的Bug解决办法

原文地址:https://gis.stackexchange.com/questions/9943/mapscale-not-being-persisted-properly-in-mxd-when-programmatically-changed-outsi?answertab=votes#tab-top


当想要修改 PageLayout 中的地图的比例尺时,一般都会想到修改 IMap 的 MapScale 属性。确实在 ArcMap 的控件中修改是可以生效的,但是在 AE 中修改时却不会生效。答主提出的办法有效的解决了这个问题。

[DllImport("User32.dll")]
public static extern int GetDesktopWindow(); 

private IMapDocument mapDocument = null;

private void ChangeMapScale()
{
    mapDocument.Open(@"C:\Temp\foo.mxd", null);

    IPageLayout pageLayout = mapDocument.PageLayout;
    IActiveView activeView = (IActiveView)pageLayout;
    IMap map = activeView.FocusMap;

    activeView = (IActiveView)mapDocument.PageLayout;
    activeView.Activate(GetDesktopWindow()); // 注意,调用了这个函数,才使得设置 MapScale 生效

    map.MapScale = value;
    activeView.Refresh();

    mapDocument.Save(true, true);
}

猜你喜欢

转载自blog.csdn.net/kowity/article/details/79504559