参考文章:http://blog.csdn.net/dszgf5717/article/details/12997163#
要在控件xtraTabPage上实现用鼠标滚轮控制图像大小的功能,则需要添加MouseWheel事件,而xtraTabPage控件中没有自带这个事件,所以需要手动添加这个实现来实现功能,两步完成。
1、在xxx.Designer.cs文件中的InitializeComponent()函数里添加添加事件代码。
this.xtraTabPage3.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.xtraTabPage3_MouseWheel);
2、在xxx.cs文件中添加事件实现函数。
private void xtraTabPage3_MouseWheel(object sender, MouseEventArgs e)
{
base.OnMouseWheel(e);
Matrix4D oldTo2DTransform = CalculateTo2DTransform1();
int compare = Math.Sign(e.Delta);
// wheel movement is forward
if (compare > 0)
{
scaleFactor *= 1.1d;
}
// wheel movement is backward
else if (compare < 0)
{
scaleFactor /= 1.1d;
}
// --- Begin of correction on the translation to zoom into mouse position.
// Comment out this section to zoom into center of model.
Point3D currentScreenPoint = new Point3D(e.X, e.Y, 0d);
Point3D modelPoint = oldTo2DTransform.GetInverse().Transform(currentScreenPoint);
Matrix4D intermediateTo2DTransform = CalculateTo2DTransform1();
Point3D screenPoint = intermediateTo2DTransform.Transform(modelPoint);
translation += (currentScreenPoint - screenPoint);
// --- End of translation correction.
CalculateTo2DTransform1();
this.xtraTabPage3.Invalidate();
}