am having problem on how to load a photograph from a folder to the form,through the picture control box in vb6 am a newbie to vb

Dani AI

Generated

As asked about loading a photo at runtime: covered the design‑time route (choose a picture in the Picture property) and pointed out the built‑in loader. Below is a slightly more robust runtime pattern (file selection, existence check, error handling, simple scaling) and a couple of practical tips that commonly solve the newbie pitfalls.

' place a PictureBox named Picture1 and a CommonDialog named CommonDialog1 on the form
Private Sub cmdSelectImage_Click()
    Dim fname As String
    CommonDialog1.Filter = "Bitmaps (*.bmp)|*.bmp|JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|GIF (*.gif)|*.gif|All files (*.*)|*.*"
    CommonDialog1.ShowOpen
    fname = CommonDialog1.FileName
    If Len(fname) = 0 Then Exit Sub   ' user cancelled

    If Dir$(fname) = "" Then
        MsgBox "Image not found: " & fname, vbExclamation
        Exit Sub
    End If

    On Error GoTo LoadErr
    Set Picture1.Picture = LoadPicture(fname)
    Picture1.Stretch = True   ' stretches to box (may distort)
    Exit Sub

LoadErr:
    MsgBox "Could not load image. Supported types typically include BMP, JPG, GIF." & vbCrLf & _
           "Error: " & Err.Description, vbCritical
End Sub

A few practical notes: use App.Path when shipping images with the EXE and join paths with a small helper so there’s no missing/backslash error. To avoid file‑lock or permission problems, set the control’s picture to Nothing before assigning a new image. PictureBox.Stretch = True scales but can distort; to preserve aspect ratio either resize the control to the picture’s aspect ratio after loading or draw the picture onto the form with PaintPicture at computed dimensions. The Common Dialog control must be present on the toolbox (Microsoft Common Dialog Control 6.0) or use the Win32 file‑open API if it isn’t available.

Recommended Answers

All 2 Replies

am having problem on how to load a photograph from a folder to the form,through the picture control box in vb6 am a newbie to vb

hmm... could you be more specific? do you have any code set up?
all you have to do is put the picture box on the form and then go to the properties and click the elipsis (...) and select a picture.

Hi,

Use this :

Picture1.Picture = LoadPicture("C:\MyPict.bmp")

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.