Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 668819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:04:58+00:00 2026-05-14T00:04:58+00:00

I am trying to make a zoom effect on a picturebox with mouse wheel.

  • 0

I am trying to make a zoom effect on a picturebox with 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 is on. When I zoom in the point, I want it always slide. Please help me add a code snippet to make it work.

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:04:59+00:00Added an answer on May 14, 2026 at 12:04 am

    You need to adjust the picture box location based on the mouse position relative to the form.

    Here is a rough but working example of how you might do this:

    var i = 5;
    var zoomfactor = new[] {.25, .33, .50, .66, .80, 1, 1.25, 1.5, 2.0, 2.5, 3.0};
    var origin = new Point(100, 100);
    var image = Image.FromFile(@"c:\example.png");
    var imgBox = new PictureBox {
            Location = origin,
            Size = image.Size,
            Image = image,
            SizeMode = PictureBoxSizeMode.StretchImage
        };
    var form = new Form {
            Size = new Size(800, 600),
            Controls = {imgBox}
        };
    form.MouseWheel += (sender, e) => {
            i += e.Delta/120;
            if (i < 0) {
                i = 0;
            }
            if (i >= zoomfactor.Length) {
                i = zoomfactor.Length - 1;
            }
            var newZoom = zoomfactor[i];
            imgBox.Width = (int) (imgBox.Image.Width*newZoom);
            imgBox.Height = (int) (imgBox.Image.Height*newZoom);
            imgBox.Left = (int) (e.X - newZoom*(e.X - origin.X));
            imgBox.Top = (int) (e.Y - newZoom*(e.Y - origin.Y));
        };
    form.ShowDialog();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to make use of the pinch touch effect
I'm trying to make a level-of-detail line chart, where the user can zoom in/out
i'm trying to make a zoom in and out of a movieclip when certain
I'm trying to make some sliding captions, something like Mosaic , but lighter. Everything
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
I'm trying to make a Google map that updates a marker as a user's
I'm trying to use the GMap.NET.WindowsForms control in my Windows forms application but I
I'm trying to make some custom Google maps info windows, but I'm getting the
I'm trying to set '+' symbol in a center of my button, but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.