PDA

Click to See Complete Forum and Search --> : Zoom-In & Zoom-Out


Ramandeep
Jun 30th, 2000, 03:21 PM
CAn any one show me by example how I may use the Plus ('+') & minus ('-') keys on the key pad to soom into & out of a picture in a picture box.

Keeping the image in proportion, like you didn't know that

Thanks in advance!!

Ram

Jun 30th, 2000, 04:08 PM
If you place your picture in an ImageBox you can use this code.

Put this in the KeyDown event of the Form.


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyAdd Then
Image1.Stretch = True
Image1.Width = Image1.Width * 2
Image1.Height = Image1.Height * 2
End If

If KeyCode = vbKeySubtract Then
Image1.Stretch = True
Image1.Width = Image1.Width / 2
Image1.Height = Image1.Height / 2
End If

End Sub


Private Sub Form_Load()

Me.KeyPreview = True
Image1.Stretch = True

End Sub

kedaman
Jun 30th, 2000, 06:26 PM
Without replacing it with a Imagebox you could use this code:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim speed As Integer

Select Case Chr(KeyCode)
Case "-"
speed = 10
Case "+"
speed = -10
Case Else
Exit Sub
End Select

With Picture1
.Picture = .Image
.PaintPicture Picture1, 0, 0, .ScaleWidth, .ScaleHeight, .ScaleWidth / speed, .ScaleHeight / speed, .ScaleWidth - .ScaleWidth / speed * 2, .ScaleHeight - .ScaleHeight / speed * 2
End With

End Sub

justify speed for your needs ;)

Jun 30th, 2000, 07:24 PM
Here is another way that is keeping the PictureBox. For this, you need to create 2 PictureBoxes. Load your Picture into Picture2.


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)


If KeyCode = vbKeyAdd Then
With Picture1
.Cls
.Width = .Width * 2
.Height = .Height * 2
.PaintPicture Picture2.Picture, 0, 0, .ScaleWidth, .ScaleHeight
End With
End If


If KeyCode = vbKeySubtract Then
With Picture1
.Cls
.Width = .Width / 2
.Height = .Height / 2
.PaintPicture Picture2.Picture, 0, 0, .ScaleWidth, .ScaleHeight
End With
End If


End Sub

Private Sub Form_Load()

Picture2.Visible = False
Me.KeyPreview = True
Picture1.AutoRedraw = True
Picture1.PaintPicture Picture2.Picture, 0, 0

End Sub