C#中鼠标滚轮事件的捕捉
2个回答
推荐于2019-01-26
展开全部
privatevoidSceneControl_OnMouseWheel(objectsender,MouseEventArgse)
{
try
{
System.Drawing.PointpSceLoc=m_SceneCtrl.PointToScreen(this.m_SceneCtrl.Location);
System.Drawing.PointPt=this.PointToScreen(e.Location);
if(Pt.X<pSceLoc.X||Pt.X>pSceLoc.X m_SceneCtrl.Width||Pt.Y<pSceLoc.Y||Pt.Y>pSceLoc.Y m_SceneCtrl.Height)
{
return;
}
doublescale=0.2;
if(e.Delta<0)scale=-0.2;
ICamerapCamera=m_SceneCtrl.Camera;
IPointpPtObs=pCamera.Observer;
IPointpPtTar=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;
m_SceneCtrl.SceneGraph.RefreshViewers();
}
catch
{
}
} 这个清楚点!! 看这个把!!
C#代码 this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel); this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel); C#代码 #region进入窗体时加载
publicFormAlarmInfoQuery()
{
InitializeComponent();
pictureBox1.ImageLocation="f:\\1.jpg";
this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
//判断是否已安装带滚轮的鼠标
//SystemInformation.MouseWheelPresent.ToString();
//获取鼠标滚轮在滚动时所获得的行数
//SystemInformation.MouseWheelScrollLines.ToString();
//判断该操作系统是否支持滚轮鼠标
//SystemInformation.NativeMouseWheelSupport.ToString();
}
#endregion #region进入窗体时加载publicFormAlarmInfoQuery(){InitializeComponent();pictureBox1.ImageLocation="f:\\1.jpg";this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);//判断是否已安装带滚轮的鼠标//SystemInformation.MouseWheelPresent.ToString();//获取鼠标滚轮在滚动时所获得的行数//SystemInformation.MouseWheelScrollLines.ToString();//判断该操作系统是否支持滚轮鼠标//SystemInformation.NativeMouseWheelSupport.ToString();}#endregion 然后写一个鼠标事件方法 C#代码 privatevoidpanel1_MouseWheel(objectsender,System.Windows.Forms.MouseEventArgse)
{
MessageBox.Show("滚动事件已被捕捉");
System.Drawing.Sizet=pictureBox1.Size;
t.Width =e.Delta;
t.Height =e.Delta;
pictureBox1.Width=t.Width;
pictureBox1.Height=t.Height;
}
{
try
{
System.Drawing.PointpSceLoc=m_SceneCtrl.PointToScreen(this.m_SceneCtrl.Location);
System.Drawing.PointPt=this.PointToScreen(e.Location);
if(Pt.X<pSceLoc.X||Pt.X>pSceLoc.X m_SceneCtrl.Width||Pt.Y<pSceLoc.Y||Pt.Y>pSceLoc.Y m_SceneCtrl.Height)
{
return;
}
doublescale=0.2;
if(e.Delta<0)scale=-0.2;
ICamerapCamera=m_SceneCtrl.Camera;
IPointpPtObs=pCamera.Observer;
IPointpPtTar=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;
m_SceneCtrl.SceneGraph.RefreshViewers();
}
catch
{
}
} 这个清楚点!! 看这个把!!
C#代码 this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel); this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel); C#代码 #region进入窗体时加载
publicFormAlarmInfoQuery()
{
InitializeComponent();
pictureBox1.ImageLocation="f:\\1.jpg";
this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
//判断是否已安装带滚轮的鼠标
//SystemInformation.MouseWheelPresent.ToString();
//获取鼠标滚轮在滚动时所获得的行数
//SystemInformation.MouseWheelScrollLines.ToString();
//判断该操作系统是否支持滚轮鼠标
//SystemInformation.NativeMouseWheelSupport.ToString();
}
#endregion #region进入窗体时加载publicFormAlarmInfoQuery(){InitializeComponent();pictureBox1.ImageLocation="f:\\1.jpg";this.MouseWheel =newSystem.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);//判断是否已安装带滚轮的鼠标//SystemInformation.MouseWheelPresent.ToString();//获取鼠标滚轮在滚动时所获得的行数//SystemInformation.MouseWheelScrollLines.ToString();//判断该操作系统是否支持滚轮鼠标//SystemInformation.NativeMouseWheelSupport.ToString();}#endregion 然后写一个鼠标事件方法 C#代码 privatevoidpanel1_MouseWheel(objectsender,System.Windows.Forms.MouseEventArgse)
{
MessageBox.Show("滚动事件已被捕捉");
System.Drawing.Sizet=pictureBox1.Size;
t.Width =e.Delta;
t.Height =e.Delta;
pictureBox1.Width=t.Width;
pictureBox1.Height=t.Height;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-28
展开全部
应该编写其OnMouseWheel事件并关联吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询