CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Smile [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
    A Full Working Sample Is Attached To This Post.
    Attached Files Attached Files

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

Featured