Results 1 to 4 of 4

Thread: Zoom-In & Zoom-Out

  1. #1

    Thread Starter
    Addicted Member Ramandeep's Avatar
    Join Date
    Feb 2000
    Posts
    158
    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

  2. #2
    Guest
    If you place your picture in an ImageBox you can use this code.

    Put this in the KeyDown event of the Form.

    Code:
    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

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Without replacing it with a Imagebox you could use this code:
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Guest
    Here is another way that is keeping the PictureBox. For this, you need to create 2 PictureBoxes. Load your Picture into Picture2.

    Code:
    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

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