Zoom In and Out in PictureBox Windows forms control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Zoom In and Out in PictureBox Windows forms control

  1. #1
    Join Date
    Jan 2005
    Posts
    1

    Zoom In and Out in PictureBox Windows forms control

    I've a windows form, on which a picturebox is placed. I've loaded images into the picturebox. I've implemented the Zoom In and Zoom out functinality. Now my problem is when I zoom in, the picturebox is not spreading equally in the form. I mean the distance between picturebox and the container form should be equal, on four sides, as I zoom in and out ( the picturebox should be exactly centered). How can I achive this? Any help? Thanks in advance.

    Here is the piece of code for Zoom In and Out

    For Zooming In :

    pictureBox1.Top= (int)(pictureBox1.Top - (pictureBox1.Height * 0.025));
    pictureBox1.Left = (int)(pictureBox1.Left - (pictureBox1.Width * 0.025));
    pictureBox1.Height = (int)(pictureBox1.Height + (pictureBox1.Height* 0.05));
    pictureBox1.Width = (int)(pictureBox1.Width + (pictureBox1.Width * 0.05));

    For Zooming Out :

    pictureBox1.Top = (int)(pictureBox1.Top + (pictureBox1.Height * 0.025));
    pictureBox1.Left = (int)(pictureBox1.Left + (pictureBox1.Width * 0.025));
    pictureBox1.Height = (int)(pictureBox1.Height - (pictureBox1.Height* 0.05));
    pictureBox1.Width = (int)(pictureBox1.Width - (pictureBox1.Width * 0.05));

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Zoom In and Out in PictureBox Windows forms control

    Usually for scrolling around like this I'd create a user control with a Panel with DockStyle = Fill which has a picturebox control which wholly encompasses the panel's area.

    Then when you zoom in resize the picturebox to the correct dimensions and call 'PerformLayout' on the Panel.

    This will cause it's scrollbars to update and enable a user to scroll around your picturebox.

    Then add the user control to your form.

    I hope you get what I mean.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jul 2014
    Posts
    1

    Re: Zoom In and Out in PictureBox Windows forms control

    Quote Originally Posted by darwen View Post
    Usually for scrolling around like this I'd create a user control with a Panel with DockStyle = Fill which has a picturebox control which wholly encompasses the panel's area.

    Then when you zoom in resize the picturebox to the correct dimensions and call 'PerformLayout' on the Panel.

    This will cause it's scrollbars to update and enable a user to scroll around your picturebox.

    Then add the user control to your form.

    I hope you get what I mean.

    Darwen.
    Hi Darwen, this does not keep the cursor(mouse) zoom position.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center