SceneControl+AE+鼠标滚轮缩放

要为SceneControl设置鼠标滚轮缩放必须定义委托,因为SceneControl没有Wheel事件,所以委托From的Wheel事件

public Form1()
 {
      InitializeComponent();
      this.MouseWheel += new MouseEventHandler(this.SC1_Wheel);  //在这个地方输入"this.MouseWheel+=”后连续按两次Tab键
}
private void SC1_Wheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
    try
    {
        pSC1.MousePointer = esriControlsMousePointer.esriPointerZoom;
        System .Drawing .Point pSceneLocation = SC1.PointToScreen(SC1.Location);
        System .Drawing .Point  Pt = this.PointToScreen(e.Location);
         if (Pt.X < pSceneLocation.X | Pt.X > pSceneLocation.X + SC1.Width | Pt.Y < pSceneLocation.Y | Pt.Y > pSceneLocation.Y + SC1.Height)
              return;
         double scale = 0.2;
         if (e.Delta < 0) scale = -0.2;
         ICamera pCamera = SC1.Camera;
         IPoint pObserver = pCamera.Observer;
         IPoint pTarget = pCamera.Target;
         pObserver.X += (pObserver.X - pTarget.X) * scale;
         pObserver.Y += (pObserver.Y - pTarget.Y) * scale;
         pObserver.Z += (pObserver.Z - pTarget.Z) * scale;
         pCamera.Observer = pObserver;
         pSC1.SceneGraph.RefreshViewers();
         this.Text = e.Delta.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
}


你可能感兴趣的:(SceneControl+AE+鼠标滚轮缩放)