views:

45

answers:

2

I'm have a picture box control and 2 Command Buttons. I have an image displayed inside the picture box.

Is it possible to zoom the image when the Zoom-in and Zoom out buttons are clicked?

Or I can even put a scroll bar. Is it possible to zoom the image according to the scroll bar movements?

I'm using VB 6.

A: 

It might be easiest to use two pic boxes, one inside the other. The 'outer' box can be thought of as a viewport into the 'inner' box, which you resize and position as needed. The effect will be the same but the coding is much simpler.

Jim Mack
+1  A: 

I assume here that you are using BMP or JPG files here.

The simple scratch method is to place an Image control in the PictureBox, initially with the property Stretch = False. Initially, it would be in the top left hand corner. After setting the Picture property to your picture object, the Image control will be resized to fit the image. Save the original width and height of the control in variables. Now set Stretch = True. You can zoom in by resizing the image using

img.Move 0, 0, sngWidth * sngMagFactor, sngHeight * sngMagFactor

Where sngMaxFactor = 4! or however much you want to zoom by.

Restore back to original size by:

img.Move 0, 0, sngWidth, sngHeight

You can also pan the zoomed image by altering the Left and Top arguments in the Move() method.

Mark Bertenshaw