-1

How do you use OpenFileDialog in choosing an image for PictureBox? (e.g. A user selects a image from the OpenFileDialog and it is shown in the PictureBox)

Can anyone help me with coding this pleasE?

Thank You

J Mahone

Mr Mahone
  • 27
  • 1
  • 8

1 Answers1

3

Hi you can do this way :

Private Sub btnBrowsePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowsePic.Click
    With OpenFileDialog1
        .InitialDirectory = "C:\"
        .Filter = "JPEGs|*.jpg|GIFs|*.gif|Bitmaps|*.bmp|AllFiles|*.*"
        .FilterIndex = 1
    End With
    If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
        With PictureBox1
            .Image = Image.FromFile(OpenFileDialog1.FileName)
            .SizeMode = PictureBoxSizeMode.CenterImage
            .BorderStyle = BorderStyle.Fixed3D
        End With
    End If
End Sub
gwt
  • 2,331
  • 4
  • 37
  • 59