Engine中如何实现鼠标滚轮缩放反置?
来自:http://zhihu.esrichina.com.cn/?/question/6666
【解决办法】:
1,禁用IMapControl的默认鼠标滚轮事件。
即设置IMapControl4.AutoMouseWheel= false;
2,重写鼠标滚轮事件。
比如在Form1_Load函数中加上this.MouseWheel += new System.Windows.Forms.MouseEventHandler(axMapControl1_OnMouseWheel);
然后重写private void axMapControl1_OnMouseWheel(object sender, MouseEventArgs e)函数,函数中内容即为鼠标滚轮缩放的代码实现。比如:
try { 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 { }