Results 1 to 7 of 7

Thread: Leting a user browse for a file?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada!
    Posts
    51

    Leting a user browse for a file?

    How do I create a program that lets a user of the program browse for a picturefile on his/her hardrive then display it in a picture box using a command button to display the file?

    I have a picture box named "picshowdisplay"

    a command named "cmd1"

    and a directory list box named "selectfile"

    This is what I had code wise.....

    Private Sub cmd1_click
    If selectfile.showdialog = dialogresult.ok then
    ' load picture into picturebox
    picshowdisplay.image= image.fromfile(selectfile.filename)
    end if
    endsub

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    I would do away with the directory list box and give them a common dialog box to work with.
    VB Code:
    1. Private Sub cmd1_Click()
    2.     On Error GoTo ErrHandler
    3.    
    4.     With cdlOpen
    5.         .CancelError = True
    6.         .Filter = "Bitmap (*.bmp)|*bmp|JPEG (*.jpg)|*.jpg|" & _
    7.                     "Graphic Interchange Format (*.gif)*.gif"
    8.         .FilterIndex = 1
    9.         .ShowOpen
    10.     End With
    11.                    
    12.     picshowdisplay.Picture = LoadPicture(cdlOpen.FileName)
    13.    
    14. Exit Sub
    15. ErrHandler:
    16. End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada!
    Posts
    51
    hmmmm. I can't find the "Openfiledialog" control...... I know its an invisible? I don't see it in the toolbar either? How do I add it invisibly?

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Right click on your toolbar and select components. From the list select "Microsoft Common Dialog Control"

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada!
    Posts
    51
    MarkT = GOD

    Thank you very much!
    http://www.aom.rtsgamer.com
    "tragedy is when I cut my finger, Comedy is when I fall into an open man-hole and die."
    Newbiest of the VB Newbs!
    HTML, VB Newbie

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada!
    Posts
    51
    what is "errhandler" and "cdlopen"?
    http://www.aom.rtsgamer.com
    "tragedy is when I cut my finger, Comedy is when I fall into an open man-hole and die."
    Newbiest of the VB Newbs!
    HTML, VB Newbie

  7. #7
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Originally posted by Longsiege
    what is "errhandler" and "cdlopen"?
    cdlopen is just the name I gave the common dialog box.

    errhandler is an error trap. With cancel error set to true, when you either click cancel or the "X" to close the dialog it raises an error. Instead of the code finishing the rest of the code in the procedure the code just skips down to ErrHandler: (referred to as a label)

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