Engine中如何实现鼠标滚轮缩放反置?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
{
}

以上是关于Engine中如何实现鼠标滚轮缩放反置?的主要内容,如果未能解决你的问题,请参考以下文章

Qtableview滚轮缩放

用js实现页面图片,以鼠标位置为中心,滚轮缩放图片

使用 ctrl + 鼠标滚轮进行缩放

在Mapbox地图中禁用鼠标滚轮缩放?

PCB Genesis 鼠标滚轮缩放与TGZ拖放 插件实现

echarts区域缩放(鼠标滚轮滚动条拉选框)