none
Open File Dialog

    Question

  •  

    Hi everyone, its me again. This time, Im having a problem with opening an image file. It opens into the specified pitcurebox. If a user clicks a button, the cursor changes appropriately. When you open a file and move the mouse over the picturebox, you get an error that the cursor isn't in the my pictures folder. All help is appreciated. Thanks in advance.
    Tuesday, November 06, 2007 12:58 AM

Answers

  • Hi B-Wade,

     

    Could your post your code and tell us the error information? You need to put openning file code into the try/catch block. Sometimes we may open the wrong file format. Here is the simple code snippet to use the openfiledialog component to open the image file and display the image in the picturebox.

    Code Block

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim openFileDialog1 As New OpenFileDialog()

    openFileDialog1.InitialDirectory = "c:\"

    openFileDialog1.Filter = "bitmap files (*.bmp)|*.bmp|Jpeg files (*.Jpeg)|*.Jpeg|All files (*.*)|*.*"

    openFileDialog1.FilterIndex = 2

    openFileDialog1.RestoreDirectory = True

    If openFileDialog1.ShowDialog() = DialogResult.OK Then

    Dim filename = openFileDialog1.FileName

    Try

    Dim img As Image = Image.FromFile(filename)

    PictureBox1.Image = img

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End If

    End Sub

     

     

    Best regards,

    Riquel

    Thursday, November 08, 2007 1:19 PM
    Moderator