?
Solved

Show Image within a VB Form with 100% zoom

Posted on 2005-05-02
3
Medium Priority
?
304 Views
Last Modified: 2012-05-05
How can I see an Image on VB Form, Is there any control or coding which I can use to see my image with scroll bars. I want to see my image with 100% zoom. If my image is bigger than the control size then I should be able to use scroll bars to see like we see our images in paint brush.
It should be within a form.

Thanks

Regards

Ajay
UK
0
Comment
Question by:ITCDevloper
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 13909815
Here is an example of scrollable picturebox with an image in it.  Create a new project and add a TextBox (Tex1), CommandButton (Command1), Horizontal Scroll Bar (HScroll1), Vertical Scroll Bar (VScroll1) and a PictureBox (Picture1).  Make Picture1 the size of the "zoomed area" you want.  Now draw a second PictureBox (Picture2), INSIDE Picture1.  Finally, add a Microsoft Windows Common Dialog Control.  Don't worry about the size or position of HScroll1, VScroll1 or Picture2 as they will be adjusted at runtime automatically.

Option Explicit

Private Sub Form_Load()
    Text1.Locked = True
    Text1.Text = ""
    Command1.Caption = "Select Image"

    With Picture2
        .Move 0, 0
        .AutoSize = True
        .Width = Picture1.Width
        .Height = Picture1.Height
    End With

    With HScroll1
        .Top = Picture1.Top + Picture1.Height
        .Left = Picture1.Left
        .Width = Picture1.Width
    End With

    With VScroll1
        .Top = Picture1.Top
        .Left = Picture1.Left + Picture1.Width
        .Height = Picture1.Height
    End With
End Sub

Private Sub Command1_Click()
    On Error GoTo cancelled
   
    CommonDialog1.CancelError = True
    CommonDialog1.DialogTitle = "Select an Image to View"
    CommonDialog1.Filter = "Image Files (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif|JPG Files (*.jpg)|*.jpg|BMP Files (*.bmp)|*.bmp|GIF Files (*.gif)|*.gif"
    CommonDialog1.ShowOpen
    Text1.Text = CommonDialog1.fileName
    Call loadImage(CommonDialog1.fileName)
cancelled:
End Sub

Private Sub loadImage(ByVal fileName As String)
    On Error Resume Next
   
    If Dir(fileName) <> "" Then
        With Picture2
            .Picture = LoadPicture(fileName)
        End With

        With HScroll1
            .Max = Picture2.Width - Picture1.Width
            If .Max < 0 Then
                .Max = 0
            End If
            .SmallChange = 1
            .LargeChange = 1
            .SmallChange = .Max / 25
            .LargeChange = .Max / 10
        End With

        With VScroll1
            .Max = Picture2.Height - Picture1.Height
            If .Max < 0 Then
                .Max = 0
            End If
            .SmallChange = 1
            .LargeChange = 1
            .SmallChange = .Max / 25
            .LargeChange = .Max / 10
        End With
    End If
    Exit Sub
End Sub

Private Sub HScroll1_Change()
    Picture2.Left = -HScroll1.Value
End Sub

Private Sub VScroll1_Change()
    Picture2.Top = -VScroll1.Value
End Sub
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13909859
Add these lines to make the image move when you drag the scrollbars instead of clicking on the arrows:

Private Sub VScroll1_Scroll()
    VScroll1_Change
End Sub

Private Sub HScroll1_Scroll()
    HScroll1_Change
End Sub
0
 

Author Comment

by:ITCDevloper
ID: 13909918
Thank you very much sir, I appreciate your early response. so far it is working fine, i will do proper testing and modify according to my requirement.

Thanks very much

Regards
Ajay
UK
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Six Sigma Control Plans
Starting up a Project

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question