[VB6] How Can I Enlarge Or Shrink A Picture, Like Zooming?
Q: How Can I Add Zooming Capabilities To My Pictures On My Form?
A: Simple really. Add an Image Control to your Form, Set the Picture property to your Picture of choice. Add a Button labeled "Enlarge". Add another Button labeled "Shrink". The 2 Buttons are part of a Control array, so both should have the same name - thus making them a COntrol Array. Add the following Code :
Code:
Option Explicit
Dim bZoom As Boolean 'Are We Zooming
Dim iHeightMin As Single 'Height
Dim iWidthMin As Single 'Width
Private Sub ZoomMe(Index As Integer)
Do
imgZoom.Visible = False
'By moving the top and left by .025 and
'the width by twice at .05 keeps the
'image proportinate and centered
Select Case Index
'Enlarging
Case 0
imgZoom.Top = imgZoom.Top - (imgZoom.Height * 0.025)
imgZoom.Left = imgZoom.Left - (imgZoom.Width * 0.025)
imgZoom.Height = imgZoom.Height + (imgZoom.Height * 0.05)
imgZoom.Width = imgZoom.Width + (imgZoom.Width * 0.05)
'Shrinking
Case 1
If imgZoom.Height <= 25 Or imgZoom.Width <= 25 Then
imgZoom.Visible = True
bZoom = False
Exit Sub
End If
imgZoom.Top = imgZoom.Top + (imgZoom.Height * 0.025)
imgZoom.Left = imgZoom.Left + (imgZoom.Width * 0.025)
imgZoom.Height = imgZoom.Height - (imgZoom.Height * 0.05)
imgZoom.Width = imgZoom.Width - (imgZoom.Width * 0.05)
End Select
imgZoom.Visible = True
DoEvents
If Not bZoom Then Exit Do
Loop
End Sub
Private Sub cmdZoomUpDown_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
bZoom = True
ZoomMe Index
End Sub
Private Sub cmdZoomUpDown_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
bZoom = False
End Sub
Private Sub Form_Load()
imgZoom.Stretch = True
iWidthMin = imgZoom.Width / 4
iHeightMin = imgZoom.Height / 4
End Sub
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.