Results 1 to 8 of 8

Thread: CommonDialog - Resolved

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    South West UK
    Posts
    245

    Resolved 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.
    A lowly programmer.

    http://www.sentinalgroup.com

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: CommonDialog

    VB Code:
    1. On Error Resume Next
    2.   dlgCommonDialog.CancelError = True
    3.   ' Set filters
    4.   dlgCommonDialog.Filter = "All Files (*.*)|*.*|Picture Files (*.jpg)|*.jpg|"  
    5. 'Display the Open dialog box
    6.   dlgCommonDialog.ShowOpen
    7.   Picture1.Picture = LoadPicture(dlgCommonDialog.FileName)

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: CommonDialog

    Quote 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:
    1. With CommonDialog1
    2.     .InitDir = "C:"
    3.     .Filter = "Jpg File (*.jpg)|*.jpg"
    4.     .DialogTitle = "Locate Your File"
    5.     .ShowOpen
    6.    
    7.     Picture1.Picture = LoadPicture(.FileName)
    8.  End With

    ok explination....

    VB Code:
    1. .InitDir = "C:"

    sets the directory we will start looking in (the root if you like)

    VB Code:
    1. .Filter = "Jpg File (*.jpg)|*.jpg"

    .filter sets what type of file we can use in our case .jpg

    VB Code:
    1. .DialogTitle = "Locate Your File"

    This is the title of the Dialog (self explanitory)

    VB Code:
    1. .ShowOpen

    This shows the Dialog as open, there are other options such as save etc

    VB Code:
    1. 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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    South West UK
    Posts
    245

    Re: CommonDialog

    That works great, now all i have to do is figure out how to resize the image to the picturebox size.
    A lowly programmer.

    http://www.sentinalgroup.com

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: CommonDialog

    Quote 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:
    1. Image1.Stretch = True
    2.     Image1.Picture = LoadPicture(.FileName)

    Hope that helps

  6. #6
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: CommonDialog

    Quote 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:
    1. Image1.Stretch = True
    2.     Image1.Picture = LoadPicture(.FileName)

    Hope that helps
    Did that help you?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    South West UK
    Posts
    245

    Resolved Re: CommonDialog

    Yep, worked a treat, vb is cool when you know the code. Thx a lot.
    A lowly programmer.

    http://www.sentinalgroup.com

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: CommonDialog

    Quote 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
  •  



Click Here to Expand Forum to Full Width