ArcEngine(四)MapControl_OnMouseDown的使用

丌官利
2023-12-01

可以通过MapControl_OnMouseDown实现一些功能, 比如读取坐标, 放大, 选择等

static string function = string.Empty;

private void MapControl_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
	IEnvelope envelope;
        IGeometry geometry;
        switch (function)
        {
        	case "coordinate":
                    MessageBox.Show("当前坐标为:" + e.x + "," + e.y+" "+mapUnit);
                    function = string.Empty;//对function进行清空
                    break;
                case "zoomIn"://track方法
                    envelope = MapControl.TrackRectangle();
                    MapControl.Extent = envelope;
                    MapControl.Refresh();
                    function = string.Empty;
                    break; 
                case "select":
                    geometry = MapControl.TrackRectangle();
                    MapControl.Map.SelectByShape(geometry, null, false);
                    MapControl.Refresh();
                    function = string.Empty;
                    break;
        }
}

private void 读取坐标ToolStripMenuItem_Click(object sender, EventArgs e)
{
        function = "coordinate";
}
private void 拉框放大ToolStripMenuItem_Click(object sender, EventArgs e)
{
        function = "zoomIn";
}
private void 拉框选择ToolStripMenuItem_Click(object sender, EventArgs e)
{
        function = "select";
}
 类似资料: