Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
May 21, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using the PaintPicture Method

It is possible to use the PaintPicture Method of the PictureBox or Form by entering different dimensions for source height/width and destination dimensions.

Here is a sample:

1) Create a new Standard EXE Project.

2) Add two PictureBoxes to Form1.

3) Make Picture1 Larger then Picture2.

4) Add any picture to the Picture1 control.

5) Past the following lines of code into Form1:
Option Explicit

Dim LastX As Single
Dim LastY As Single

Public Sub ZoomPicture(Picture As StdPicture, X As Single, 
Y As Single, 
ZoomWindow As PictureBox, Optional Factor As Byte = 2)
    ZoomWindow.PaintPicture Picture, 0, 0, 
ZoomWindow.ScaleHeight, X, Y, ZoomWindow.ScaleWidth / 
ZoomWindow.ScaleHeight / Factor, vbSrcCopy
End Sub

Private Sub Picture1_MouseMove(Button As Integer, 
Shift As Integer, X As 
Single, Y As Single)
    ZoomPicture Picture1.Image, X, Y, Picture2
    LastX = X
    LastY = Y
End Sub

Private Sub Picture2_Paint()
    ZoomPicture Picture1.Image, LastX, LastY, Picture2
End Sub
Andreas Hillqvist
Thanks for your registration, follow us on our social networks to keep up-to-date