这是我的代码。
我可以缩放图片框,但不能缩放。旋转鼠标滚轮时如何缩放到鼠标点?
变量是:-
private double m_dZoomscale = 1.0; //THIS IS THE ZOOM SCALE TO WHICH EACH OBJECT
//ARE ZOOMED IN THE CANVAS
public static double s_dScrollValue = .01;
//scale factor value for mouse scroll zooming
油漆代码是:-
private void m_Picturebox_Canvas_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.ScaleTransform((float)m_dZoomscale, (float)m_dZoomscale);
}
主要代码是:-
protected override void OnMouseWheel(MouseEventArgs mea)
{
m_Picturebox_Canvas.Focus();
if (m_Picturebox_Canvas.Focused == true)
{
if (mea.Delta > 0)
{
ZoomInScroll();
}
else if (mea.Delta < 0)
{
ZoomOutScroll();
}
}
}
子功能如下:-
//FUNCTION FOR MOUSE SCROL ZOOM-IN
private void ZoomInScroll()
{
m_dZoomscale = m_dZoomscale + s_dScrollValue;
m_Picturebox_Canvas.Invalidate();
}
//FUNCTION FOR MOUSE SCROL ZOOM-IN
private void ZoomOutScroll()
{
m_dZoomscale = m_dZoomscale - s_dScrollValue;
m_Picturebox_Canvas.Invalidate();
}