mapcontrol的鼠标样式

本文介绍在C#中如何设置MapControl组件的鼠标指针样式,包括默认样式、放大缩小、拖动等多种样式选项。

C#里直接用cursor就行了

mapcontrol的鼠标样式

this.axMapControl1.MousePointer=esriControlsMousePointer.esriPointerDefault;还可以是下面的值:

esriControlsMousePointer Constants

Control mouse pointer options.

esriPointerParentWindow-1pointer specified on the parent window or form.
esriPointerDefault0Default pointer, same as arrow.
esriPointerArrow1Standard arrow.
esriPointerCrosshair2Crosshair.
esriPointerIBeam3I-Beam.
esriPointerIcon4Icon.
esriPointerSize5Size, four-pointed arrow pointing north, south, east and west.
esriPointerSizeNESW6Size NE-SW, double arrow pointing north-east and south-west.
esriPointerSizeNS7Size N-S, double arrow pointing north and south.
esriPointerSizeNWSE8Size NW-SE, double arrow pointing north-west and south-east.
esriPointerSizeWE9Size W-E, double arrow pointing west and east.
esriPointerUpArrow10Arrow pointing vertically up.
esriPointerHourglass11Hourglass, wait cursor.
esriPointerNoDrop12Circle with slash through it or a no entry sign.
esriPointerArrowHourglass13Standard arrow and small hourglass.
esriPointerArrowQuestion14Arrow and question mark.
esriPointerSizeAll15Size all, a four-pointed arrow pointing north, south, east and west.
esriPointerZoom50Zoom, a magnifying glass.
esriPointerZoomIn51Zoom in, a magnifying glass with a plus sign.
esriPointerZoomOut52Zoom out, a magnifying glass with a minus sign.
esriPointerPan53Pan, a hand.
esriPointerPanning54Panning, a clenched hand.
esriPointerIdentify55Identify, arrow with information symbol.
esriPointerLabel56Label, arrow with letter A.
esriPointerHotLink57Hot-Link, lightening strike.
esriPointerPencil58Pencil.
esriPointerHand59Hand, closed hand with index finger pointing vertically.
esriPointerPageZoomIn60Page zoom In, magnifying glass with plus sign and a small page.
esriPointerPageZoomOut61Page zoom out, magnifying glass with minus sign and a small page.
esriPointerPagePan62Page pan, open hand with page symbol.
esriPointerPagePanning63Page pan, closed hand with page symbol.
esriPointerCustom99Custom icon specified by the MouseIcon property.

转载于:https://www.cnblogs.com/lcxu2/archive/2011/03/11/2004002.html

修改代码,使绘制矩形的起点为在axMC上点击第一个点 using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using System; using System.Collections.Generic; using System.Windows.Forms; namespace DEMO { public partial class SpatialQueryForm : Form { private FormMain _mainForm; private AxMapControl _mapControl; private IGeometry _queryGeometry; // 空间关系字典 private readonly Dictionary<string, esriSpatialRelEnum> spatialRelations = new Dictionary<string, esriSpatialRelEnum> { { "相交", esriSpatialRelEnum.esriSpatialRelIntersects }, { "包含", esriSpatialRelEnum.esriSpatialRelContains }, { "被包含", esriSpatialRelEnum.esriSpatialRelWithin }, { "相接", esriSpatialRelEnum.esriSpatialRelTouches } }; public SpatialQueryForm(FormMain mainForm) { InitializeComponent(); _mainForm = mainForm; _mapControl = _mainForm.MapControl; lblStatus.Text = "未绘制"; } private void SpatialQueryForm_Load(object sender, EventArgs e) { // 加载图层 LoadLayers(); // 加载空间关系 comBSpatialRel.Items.Clear(); foreach (var rel in spatialRelations.Keys) { comBSpatialRel.Items.Add(rel); } comBSpatialRel.SelectedIndex = 0; // 默认选择"相交" } private void LoadLayers() { comBLayer.Items.Clear(); for (int i = 0; i < _mapControl.LayerCount; i++) { ILayer layer = _mapControl.get_Layer(i); if (layer is IFeatureLayer) comBLayer.Items.Add(layer.Name); } if (comBLayer.Items.Count > 0) comBLayer.SelectedIndex = 0; } public void ReceiveDrawnGeometry(IGeometry geometry) { _queryGeometry = geometry; lblStatus.Text = "已接收绘制图形,点击查询按钮执行"; } private void btnDraw_Click(object sender, EventArgs e) { if (_mapControl == null) return; // 重置状态 lblStatus.Text = "未绘制"; try { _mapControl.MousePointer = esriControlsMousePointer.esriPointerCrosshair; lblStatus.Text = "请在地图上绘制矩形..."; // 绘制矩形(起点为点击的第一个点) _queryGeometry = _mapControl.TrackRectangle(); if (_queryGeometry != null && !_queryGeometry.IsEmpty) { lblStatus.Text = "矩形绘制完成,点击查询按钮执行"; } else { lblStatus.Text = "未绘制矩形"; } } catch (Exception ex) { MessageBox.Show($"绘制错误: {ex.Message}"); lblStatus.Text = "绘制失败"; } finally { _mapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; } } private void btnQuery_Click(object sender, EventArgs e) { if (comBLayer.SelectedIndex == -1) { MessageBox.Show("请选择图层"); return; } if (_queryGeometry == null || _queryGeometry.IsEmpty) { MessageBox.Show("请先绘制查询矩形"); return; } string layerName = comBLayer.SelectedItem.ToString(); IFeatureLayer featureLayer = null; for (int i = 0; i < _mapControl.LayerCount; i++) { if (_mapControl.get_Layer(i).Name == layerName) { featureLayer = _mapControl.get_Layer(i) as IFeatureLayer; break; } } if (featureLayer == null) { MessageBox.Show("未找到指定图层"); return; } // 获取选择的空间关系 string selectedRel = comBSpatialRel.SelectedItem.ToString(); esriSpatialRelEnum spatialRel = spatialRelations[selectedRel]; try { ISpatialFilter spatialFilter = new SpatialFilterClass { Geometry = _queryGeometry, SpatialRel = spatialRel, GeometryField = featureLayer.FeatureClass.ShapeFieldName }; IFeatureSelection featureSelection = (IFeatureSelection)featureLayer; featureSelection.Clear(); // 执行选择 featureSelection.SelectFeatures(spatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false); // 刷新视图 _mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); _mapControl.ActiveView.Refresh(); // 显示结果 int count = featureSelection.SelectionSet.Count; lblStatus.Text = $"查询完成,选中 {count} 个要素"; MessageBox.Show($"空间查询完成,共选中 {count} 个要素", "查询结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show($"查询失败: {ex.Message}"); lblStatus.Text = "查询失败"; } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } // 图层选择变更时清除查询结果 private void comBLayer_SelectedIndexChanged(object sender, EventArgs e) { ClearSelection(); } // 清除所有选择 private void ClearSelection() { try { for (int i = 0; i < _mapControl.LayerCount; i++) { IFeatureLayer featureLayer = _mapControl.get_Layer(i) as IFeatureLayer; if (featureLayer != null) { IFeatureSelection featureSelection = featureLayer as IFeatureSelection; featureSelection.Clear(); } } // 刷新地图 _mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); _mapControl.ActiveView.Refresh(); // 重置状态 lblStatus.Text = "未绘制"; _queryGeometry = null; } catch (Exception ex) { MessageBox.Show($"清除选择失败: {ex.Message}"); } } private void comBSpatialRel_SelectedIndexChanged(object sender, EventArgs e) { ClearSelection(); } } }
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值