Dialoghie box problem

  • Thread starter Thread starter Poppy
  • Start date Start date
P

Poppy

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
 
Remove the first ofdImage1.ShowDialog() line.
Within the If() statement you open the dialog a second time!

Erik
 
Poppy said:
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'd call Showdialog only once.
 
Back
Top