My application needs control displaying bitmaps (jpg) but also zooming and panning them (so if you press mouse button you can 'move' zoomed picture inside frame)
What I did was placing panel at the Form, then pictureBox inside panel (anchored Top,Left).
So if I need zoom it I'm just executing below code from Zoom buttons events:
private void ZommInOut(bool zoom) {
int zoomRatio = 10; // percent
int widthZoom = pBox.Width * zoomRatio /100;
int heightZoom = pBox.Height * zoomRatio /100;
if (zoom) {
widthZoom *= -1;
heightZoom *= -1;
}
pBox.Width += widthZoom;
pBox.Height += heightZoom;
}
Works petty well. Image is zoomed, panel displaying scrollbars - so I have working simple panning functionality.
What is missing to me is possibility to use mouse for panning - I'd like to drag picture in any direction to see other part of picture (as eg Acrobat Reader does).
I've looked for the way to use MouseMove event and change scrollbars programically but I couldn't manage that.
Any suggestion(s)?