要为SceneControl设置鼠标滚轮缩放必须定义委托,因为SceneControl没有Wheel事件,所以委托From的Wheel事件
public Form1()
{
InitializeComponent();
this.MouseWheel += new MouseEventHandler(this.SceneControl_MouseWheel); //在这个地方输入"this.MouseWheel+=”后连续按两次Tab键
}
private void SceneControl_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
axSceneControl1.MousePointer = esriControlsMousePointer.esriPointerZoom;
System.Drawing.Point pSceneLocation = axSceneControl1.PointToScreen(axSceneControl1.Location);
System.Drawing.Point Pt = axSceneControl1.PointToScreen(e.Location);
if (Pt.X < pSceneLocation.X | Pt.X > pSceneLocation.X + axSceneControl1.Width | Pt.Y < pSceneLocation.Y | Pt.Y > pSceneLocation.Y + axSceneControl1.Height)
return;
double scale = 0.2;
if (e.Delta < ) scale = -0.2;
ICamera pCamera = axSceneControl1.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;
axSceneControl1.SceneGraph.RefreshViewers();
//this.Text = e.Delta.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}