Results 1 to 4 of 4

Thread: Open File Dialogue problem

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Open File Dialogue problem

    I use the following code to open a dialogue box. The user chooses a file and that image file is used as the source for the picturebox control :

    Private Sub btnChoose1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChoose1.Click
    Dim ofdImage1 As New OpenFileDialog()
    ofdImage1.Filter = "Picture Files|*.bmp;*.jpg;*.jpeg;*.gif;*.ico"
    ofdImage1.ShowDialog()
    If (ofdImage1.ShowDialog() = DialogResult.OK) Then
    Me.picImage1.Image = New Bitmap(ofdImage1.FileName)
    End If
    End Sub

    The problem is that if I choose from the file dialogue box, or hit cancel, the dialogue box appears a second time.

    I dont understand.

    Any ideas folks ?

    TIA

    Parksie

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    remove this call ofdImage1.ShowDialog() and it should work as you want .

  3. #3
    Addicted Member
    Join Date
    Nov 2003
    Location
    India
    Posts
    227
    Try this

    VB Code:
    1. Private Sub btnChoose1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChoose1.Click
    2. Dim ofdImage1 As New OpenFileDialog()
    3. ofdImage1.Filter = "Picture Files|*.bmp;*.jpg;*.jpeg;*.gif;*.ico"
    4. If (ofdImage1.ShowDialog() = DialogResult.OK) Then
    5. Me.picImage1.Image = New Bitmap(ofdImage1.FileName)
    6. End If
    7. End Sub
    See you,
    -Jai
    [Friends Never Say Good Bye]

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Jaiboy
    Try this

    VB Code:
    1. Private Sub btnChoose1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChoose1.Click
    2. Dim ofdImage1 As New OpenFileDialog()
    3. ofdImage1.Filter = "Picture Files|*.bmp;*.jpg;*.jpeg;*.gif;*.ico"
    4. If (ofdImage1.ShowDialog() = DialogResult.OK) Then
    5. Me.picImage1.Image = New Bitmap(ofdImage1.FileName)
    6. End If
    7. End Sub
    lol , this is exactly what I said .

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