ArcEngine默认鼠标滚轮事件向上是缩小,向下是放大。现在修改为向上是放大,向下是缩小。
两种方法1.修改注册表
2.重写鼠标滚轮事件
第一种:
public frmMainUI()
{
InitializeComponent();
//注册MapControl方向
this.ReverseMouseWheel();
}
/// <summary>
/// MapControl放大缩小方向反转
/// </summary>
private void ReverseMouseWheel()
{
try
{
RegistryKey setKey = Registry.CurrentUser.OpenSubKey(@"Software\ESRI\ArcMap\Settings", true);
if (setKey != null)
{
if (setKey.GetValue("ReverseMouseWheel") == null)
{
setKey.SetValue("ReverseMouseWheel", 0, RegistryValueKind.DWord);
}
else if (setKey.GetValue("ReverseMouseWheel").ToString() != "0")
{
setKey.SetValue("ReverseMouseWheel", 0);
}
}
}
catch { }
}
第二种:
using ESRI.ArcGIS.Geometry;
private void Form1_Load(object sender, EventArgs e)
{
axMapControl1.AutoMouseWheel = false; //禁止axMapControl使用滚轮
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(axMapControl1_OnMouseWheel); //加载鼠标滚轮缩放事件
}
/// 重写鼠标滚轮缩放事件,前滚放大,后滚缩小
private void axMapControl1_OnMouseWheel(object sender, MouseEventArgs e)
{
IEnvelope mEnvelope = null;
IPoint mPoint = new PointClass();//缩放中心点
IPoint mousePoint = null;//鼠标点击点
try
{
mEnvelope = axMapControl1.ActiveView.Extent;
mPoint.X = (mEnvelope.XMax + mEnvelope.XMin) / 2;
mPoint.Y = (mEnvelope.YMax + mEnvelope.YMin) / 2;
mousePoint = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.X, e.Y);
double moveDisX = mousePoint.X - (mEnvelope.XMax + mEnvelope.XMin) / 2;
double moveDisY = mousePoint.Y - (mEnvelope.YMax + mEnvelope.YMin) / 2;
mEnvelope.CenterAt(mousePoint);
if (e.Delta > 0)
{
mEnvelope.Width = mEnvelope.Width * 0.8;
mEnvelope.Height = mEnvelope.Height * 0.8;
mPoint.X = mousePoint.X - moveDisX * 0.8;
mPoint.Y = mousePoint.Y - moveDisY * 0.8;
}
else if (e.Delta < 0)
{
mEnvelope.Width = mEnvelope.Width * 1.25;
mEnvelope.Height = mEnvelope.Height * 1.25;
mPoint.X = mousePoint.X - moveDisX * 1.25;
mPoint.Y = mousePoint.Y - moveDisY * 1.25;
}
mEnvelope.CenterAt(mPoint);
axMapControl1.ActiveView.Extent = mEnvelope;
axMapControl1.ActiveView.Refresh();
}
catch
{
}
}