|
-
Feb 11th, 2005, 07:16 AM
#1
Thread Starter
Addicted Member
CommonDialog - Resolved
I am using a CommonDialog so the user can find a jpg file. I have a picture control on the form and what i would like to do is enable the user to select the jpg and for it to appear in the picture conmtrol along with the path of the image in a text box.
Does anyone have a snippit of code that can help me with this?
Last edited by HELPmyVB; Feb 11th, 2005 at 08:00 AM.
-
Feb 11th, 2005, 07:44 AM
#2
Re: CommonDialog
VB Code:
On Error Resume Next
dlgCommonDialog.CancelError = True
' Set filters
dlgCommonDialog.Filter = "All Files (*.*)|*.*|Picture Files (*.jpg)|*.jpg|"
'Display the Open dialog box
dlgCommonDialog.ShowOpen
Picture1.Picture = LoadPicture(dlgCommonDialog.FileName)
-
Feb 11th, 2005, 07:45 AM
#3
Re: CommonDialog
 Originally Posted by HELPmyVB
I am using a CommonDialog so the user can find a jpg file. I have a picture control on the form and what i would like to do is enable the user to select the jpg and for it to appear in the picture conmtrol along with the path of the image in a text box.
Does anyone have a snippit of code that can help me with this?
Ok I have never used this control before (wierd or what) anyways I decided to have a play with it and i came up with this, and it works great 
VB Code:
With CommonDialog1
.InitDir = "C:"
.Filter = "Jpg File (*.jpg)|*.jpg"
.DialogTitle = "Locate Your File"
.ShowOpen
Picture1.Picture = LoadPicture(.FileName)
End With
ok explination....
sets the directory we will start looking in (the root if you like)
VB Code:
.Filter = "Jpg File (*.jpg)|*.jpg"
.filter sets what type of file we can use in our case .jpg
VB Code:
.DialogTitle = "Locate Your File"
This is the title of the Dialog (self explanitory)
This shows the Dialog as open, there are other options such as save etc
VB Code:
Picture1.Picture = LoadPicture(.FileName)
this loads the filepath (we just got from the dialog) into the picture box 
Ok i hope that helps if you have any further questions please ask 
Pino
-
Feb 11th, 2005, 07:48 AM
#4
Thread Starter
Addicted Member
Re: CommonDialog
That works great, now all i have to do is figure out how to resize the image to the picturebox size.
-
Feb 11th, 2005, 07:49 AM
#5
Re: CommonDialog
 Originally Posted by HELPmyVB
That works great, now all i have to do is figure out how to resize the image to the picturebox size.
You could change the control to be an image control rather than a picture box and this would work
VB Code:
Image1.Stretch = True
Image1.Picture = LoadPicture(.FileName)
Hope that helps
-
Feb 11th, 2005, 07:58 AM
#6
Re: CommonDialog
 Originally Posted by Pino
You could change the control to be an image control rather than a picture box and this would work
VB Code:
Image1.Stretch = True
Image1.Picture = LoadPicture(.FileName)
Hope that helps
Did that help you?
-
Feb 11th, 2005, 07:59 AM
#7
Thread Starter
Addicted Member
Re: CommonDialog
Yep, worked a treat, vb is cool when you know the code. Thx a lot.
-
Feb 11th, 2005, 08:06 AM
#8
Re: CommonDialog
 Originally Posted by HELPmyVB
Yep, worked a treat, vb is cool when you know the code. Thx a lot.
Yea its just a case of getting to grips with how it works (I have never used that control before) but looking at the propertys etc you get used to thinks like that 
Glad you sorted it, if you could mark this resolved and carry out any ratings.
Pino
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
|