ArcEngine反转鼠标滚轮方向

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
            {
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值