|
-
Mar 23rd, 2002, 06:53 PM
#1
Thread Starter
Member
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
-
Mar 23rd, 2002, 07:23 PM
#2
I would do away with the directory list box and give them a common dialog box to work with.
VB Code:
Private Sub cmd1_Click()
On Error GoTo ErrHandler
With cdlOpen
.CancelError = True
.Filter = "Bitmap (*.bmp)|*bmp|JPEG (*.jpg)|*.jpg|" & _
"Graphic Interchange Format (*.gif)*.gif"
.FilterIndex = 1
.ShowOpen
End With
picshowdisplay.Picture = LoadPicture(cdlOpen.FileName)
Exit Sub
ErrHandler:
End Sub
-
Mar 23rd, 2002, 08:28 PM
#3
Thread Starter
Member
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?
-
Mar 23rd, 2002, 08:32 PM
#4
Right click on your toolbar and select components. From the list select "Microsoft Common Dialog Control"
-
Mar 23rd, 2002, 08:56 PM
#5
Thread Starter
Member
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
-
Mar 24th, 2002, 07:34 PM
#6
Thread Starter
Member
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
-
Mar 24th, 2002, 08:56 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|