Main Menu

ZoomIn

Started by fdcnred, May 16, 2014, 06:36:15 PM

Previous topic - Next topic

fdcnred

I'm trying to integrate ImageBox in a quick viewer.  It's a great control.  The only problem I'm currently having is that the ZoomIn and ZoomOut always resets the scroll bars to top left.  Is there a way to zoom in with these functions and not reset the scroll bars?

Thanks,
Darren

Richard Moss

Darren,

Thanks for your message! Are you using the NuGet package or the source version? If it's the source, try adding a new method similar to the following:

    public void ZoomInEx()
    {
      Point currentPixel;
      int currentZoom;
      Point relativePoint;

      relativePoint = this.CenterPoint;
      currentPixel = this.PointToImage(relativePoint);
      currentZoom = this.Zoom;

      this.ZoomIn();

      if (this.Zoom != currentZoom)
      {
        this.ScrollTo(currentPixel, relativePoint);
      }
    }


This will store the current position, apply the zoom, then reset the position to match - it's how the control does this in various places. You could then add a similar method for zooming out.

If you're using the package, you could add an extension method or stack method to do the same thing.

I do plan on addressing this properly in the next update as it's a bit daft that it's not exposed for programmatic access as opposed to user input.

Hope this helps!

Regards;
Richard Moss
Read "Before You Post" before posting. Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

fdcnred

Perfect.  Thank you.  I have the source code but am using NuGet for my current project and got this to work.

Darren

fdcnred

Richard,
Where to I make this fix in the latest Github version?  The code has changed fairly significantly and zoomin/out doesn't work right.

Thanks,
Darren

Richard Moss

Hello,

What exactly are you trying to change and how is the zoom in/out not working correctly?

Regards;
Richard Moss
Read "Before You Post" before posting. Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

fdcnred

Sorry I didn't make myself clear.  As discussed previously in this thread, if I zoom in with a rectangle zoom and then I zoom out with the magnifying glass icon the view/image always resets to the top left corner.  I'm like to see the ImageBox control modified so that it doesn't reset to the top left on zoom in or zoom out. 

I use the ZoomInEx() method as described above but what always happens is I get the latest code from one of your repositories then I try and run it and notice it's "broke" and have to figure out what I did to fix it last time.  Last time could be many moons ago and the code base could be completely different so it's more difficult to figure out.

I love ImageBox.

Thanks,
Darren

Richard Moss

Darren,

Thanks for the clarification. I don't recall making any drastic changes that would break it, but I'll take a look and let you know what's up!

Regards;
Richard Moss
Read "Before You Post" before posting. Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

Richard Moss

Darren,

I've just pushed a new update to GitHub. I haven't updated to the NuGet package yet, should probably wait until I am sure I haven't broken anything!

I've refactored the zoom code so that by default it will always try and preserve the original center point  (along with new ZoomIn and ZoomOut overloads that let you specify how you want the operation to behave if required). Regardless of if using the keyboard or mouse (or custom actions via ZoomIn/ZoomOut) it now goes through the same place.

You shouldn't need to use your custom "Ex" methods any more.

Give this update a whirl and let me know if it solves your problem - I didn't see anything obvious, but who knows.
Read "Before You Post" before posting. Do not send me private messages. Do not expect instant replies.

All responses are hand crafted. No AI involved. Possibly no I either.

fdcnred

Looks good.  Thanks so much for the work.  This will make incorporating ImageBox much easier in future projects.