(VB.Net源码)
由于Scenecontrol中没有响应滚轮滑动的事件,所以首先得写一个滚轮滑动事件
AxSceneControl1_Wheel
然后,在Load时,添加鼠标滚轮滑动句柄
AddHandler Me.MouseWheel, AddressOf AxSceneControl1_Wheel
这样就将鼠标滚轮滑动与AxSceneControl1_Wheel挂接起来了
然后在AxSceneControl1_Wheel中写入操作语句
Try
Dim pSceLoc As System.Drawing.Point = AxSceneControl1.PointToScreen(Me.AxSceneControl1.Location)
Dim Pt As System.Drawing.Point = Me.PointToScreen(e.Location)
If Pt.X < pSceLoc.X Or Pt.X > pSceLoc.X + AxSceneControl1.Width Or Pt.Y < pSceLoc.Y Or Pt.Y > pSceLoc.Y + AxSceneControl1.Height Then Exit Sub
Dim scale As Double = 0.2
If e.Delta < 0 Then scale = -0.2
Dim pCamera As ICamera = AxSceneControl1.Camera
Dim pPtObs As IPoint = pCamera.Observer
Dim pPtTar As IPoint = pCamera.Target
pPtObs.X += (pPtObs.X - pPtTar.X) * scale
pPtObs.Y += (pPtObs.Y - pPtTar.Y) * scale
pPtObs.Z += (pPtObs.Z - pPtTar.Z) * scale
pCamera.Observer = pPtObs
AxSceneControl1.SceneGraph.RefreshViewers()
Catch ex As Exception
End Try
这样就可以顺利响应鼠标滚轮滑动的放大与缩小了,Map、Globe中也可以如此实现,其它不支持鼠标滚轮事件的控件也可以这样做
posted on 2008-05-13 08:15
王者之魂 阅读(173)
评论(1) 编辑 收藏