C# i am trying to make a zoom effect

Posted by thrillercd on Stack Overflow See other posts from Stack Overflow or by thrillercd
Published on 2010-03-12T10:40:47Z Indexed on 2010/03/12 10:47 UTC
Read the original article Hit count: 460

Filed under:
|
|

Pls help! i am trying to make a zoom effect on a picturebox by mouse wheel.Everything is ok except that when i use mouse middle button to zoom in or zoom out it is ok but it does not zoom in or zoom out the point which the mouse cursor on.when i zoom in the point what i want it always slide .Pls help me to add a snippet code to make it right working. Here is my code. I am trying to make a zoom effect on a picturebox by mouse wheel. Everything is ok except that when I use mouse middle button to zoom in or zoom out it is ok but it does not zoom in or zoom out the point which the mouse cursor on.

When I zoom in the point what I want it always slide. Please help me to add a snippet code to make it right working.

Here is my code:

int i = 5;
int index = 10;
private double[] zoomfactor = { .25, .33, .50, .66, .80, 1, 1.25, 1.5, 2.0, 2.5, 3.0 };

private void Zoom(int i)
{

  double new_Zoom = zoomfactor[i];

  imgBox.Width = Convert.ToInt32(imgBox.Image.Width * new_Zoom);
  imgBox.Height = Convert.ToInt32(imgBox.Image.Height * new_Zoom);

}

private void On_wheel(object sender, System.Windows.Forms.MouseEventArgs e)
{
  i = i + e.Delta / 120;
  if (i < 0)
  {
    i = 0;
  }
  else
  {
    if (i <= index)
      i = i;
    else
      i = index;
   }
   Zoom(i);
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about zoom