How Can I Display an Image Using VB.NET?

  • Thread starter Thread starter mcknia07
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 2K views
mcknia07
Messages
284
Reaction score
7
Public Class Form1

Private Sub btnDisplayPic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayPic.Click

OpenFileDialog1.Filter = "Image Files (*.jpg)|*jpg"

OpenFileDialog1.ShowDialog()

Try
txtPicFile.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
Catch myfilenotfound As System.IO.FileNotFoundException
MessageBox.Show("File not found - select a different file!")

Catch ex As Exception
MessageBox.Show("Unexpected error!")

End Try


End Sub
End Class


here is my code...
 
on Phys.org
Public Class Form1

Private Sub btnDisplayPic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayPic.Click

OpenFileDialog1.Filter = "Image Files (*.jpg)|*jpg"

if dlg.ShowDialog() = DialogResult.OK
imgPhoto.Image = new Bitmap(dlg.OpenFile());
end if

End Sub
End Class