-
Picture box problem
Hello, I have another problem with my project. I have a form, that saves image from computer to databese. Saving, deleting all works except this. When you click button to open windows search (to find picture from computer), if you click "Cancel" it shows a mistake. Here is my code:
Code:
Private Sub ButtonOPEN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOPEN.Click
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
ChosenPicturePictureBox.Image = Image.FromFile(TextBox1.Text)
End Sub
So if I click "Cancel", application stop working and line this row of code: ChosenPicturePictureBox.Image = Image.FromFile(TextBox1.Text) so that is here mistake. Open button works normal.
Also, how do I prevent to chosing other files exceot JPEG files.
Realy thanks for all idea.
-
Re: Picture box problem
You need to check the dialog result and set its filter property, try the following code
Code:
Private Sub ButtonOPEN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOPEN.Click
Dim dlg As New OpenFileDialog
dlg.Filter = "Picture File (*.jpg)|*.jpg|Picture File (*.jpeg)|*.jpeg|All files (*.*)|*.*"
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = dlg.FileName
ChosenPicturePictureBox.Image = Image.FromFile(dlg.FileName)
End If
End Sub
-
Re: Picture box problem
4x2y Thank you, you are the best :bigyello: