Results 1 to 3 of 3

Thread: Picture box problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    120

    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.

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    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



  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    120

    Re: Picture box problem

    4x2y Thank you, you are the best

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width