Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve File Path Of An Image In A PictureBox

Status
Not open for further replies.

CSpannos

IS-IT--Management
Mar 21, 2001
32
US
Hello,

After an image has been placed in a PictureBox, I am trying to make it so that when you click on the PictureBox, the image will pop up in the Windows Picture Viewer.

Code:
Private Sub PictureBoxPreviewImagePreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBoxPreviewImagePreview.Click
        Dim filepath As String
        'filepath = PictureBoxPreviewImagePreview.Image
        Try
            Call Shell("rundll32.exe C:\WINDOWS\System32\shimgvw.dll,ImageView_Fullscreen" & filepath, AppWinStyle.Hide)
        Catch ex As System.Exception  'watch for exception
            MsgBox("Cannot open the specified file.", MsgBoxStyle.OKOnly, "Preview Error")
        End Try
    End Sub

How do I retrieve the path and filename of the Image currently in the PictureBox?

Thanks!
Kosta
 
Why not stick the filepath into the Tag property of the PictureBox control when the Image is assigned ?

You can then retrieve it at any time:

filepath = PictureBoxPreviewImagePreview.Tag.ToString
 
I agree with SHelton. If you add the picture in the designer, it will be compiled into your program. So I don't know what good the path would do you. If you are loading the image from a file in code, then you can even make a string and assign the path to the string when you assign it to the picture's image property, and just used the variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top