Results 1 to 2 of 2

Thread: How can i zoom in on a picturebox and draw on it?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999


    Do you have any idea how i could go about zooming in on a picture box? Im currently using the paintpicture method except it causes me a problem. I need to draw on the zoomed picture (im using the line command) , but when i zoom out (redraw it with paintpicture) it erases the lines i drew. I only have one month of programming under my belt and am confused. If you know an answer i would appreciate it.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Red Wing, MN, USA


    This is only a very basic example, but I think it demonstrates the functionality you're looking for:

    Add 2 Pictureboxes to a Form and Load a Picture into Picture1..
    Private Sub Form_Load()
        Picture1.AutoRedraw = True
        Picture2.AutoRedraw = True
        Picture2.Visible = False
        Picture1.ScaleMode = vbPixels
        Picture2.ScaleMode = vbPixels
        Picture2.Move 0, 0, Picture1.Width, Picture2.Height
        Picture1.MousePointer = vbCrosshair
    End Sub
    Private Sub Command1_Click()
        Static bZoom As Boolean
        bZoom = Not bZoom
        If bZoom Then
            'Zoom in 10x on Top Left of Image
            With Picture1
                Picture2 = Picture1
                .PaintPicture .Picture, 0, 0, .ScaleWidth, .ScaleHeight, 0, 0, .ScaleWidth / 10, .ScaleHeight / 10
                Picture1 = .Image
            End With
            'Zoom Back out to 100%
            Picture1 = Picture2.Image
        End If
    End Sub
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = vbLeftButton Then
            'Draw on Normal Sized Picture
            Picture2.PSet (X / 10, Y / 10)
            With Picture1
                'Recopy Zoomed Image to Give Illusion of Drawing on Zoomed Image.. 
                .PaintPicture Picture2.Image, 0, 0, .ScaleWidth, .ScaleHeight, 0, 0, .ScaleWidth / 10, .ScaleHeight / 10
            End With
        End If
    End Sub

    Aaron Young
    Analyst Programmer

Posting Permissions

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

Click Here to Expand Forum to Full Width