gis地图界面利用栈实现撤销重做操作

 

操作类

public class operate
{
private Stack<IElement> nows = new Stack<IElement>();
private IElement nl;
private IElement xElement;

public operate()
{

}

//撤销
public void rollback(Stack<IElement> history, IMapControl3 axmap, IGraphicsContainer pgra)
{
nl=history.Pop();
pgra.DeleteElement(nl);
axmap.ActiveView.Refresh();
}

//进入重做栈
public Stack<IElement> fallbackstack()
{
nows.Push(nl);
return nows;
}

//重做
public Stack<IElement> fallback(IMapControl3 axmap, IGraphicsContainer pgra)
{
xElement = nows.Pop();
pgra.AddElement(xElement, 0);
axmap.ActiveView.Refresh();
return nows;
}

//进入撤消栈
public Stack<IElement> rollbackstack(Stack<IElement> history)
{
history.Push(xElement);
return history;
}


}

//界面命令

private Stack<IElement> history;//撤销
private Stack<IElement> now;//重做
private ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = null;
private operate oper;
private IGraphicsContainer pgra;

private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
{
oper.rollback(history, m_mapControl, pgra);
now = oper.fallbackstack();
}

private void 重做ToolStripMenuItem_Click(object sender, EventArgs e)
{
now = oper.fallback(m_mapControl, pgra);
history = oper.rollbackstack(history);
}

posted @ 2013-05-16 09:26  之远  阅读(340)  评论(0编辑  收藏  举报