Dialoghie box problem

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
 
E

Erik Vegting

Remove the first ofdImage1.ShowDialog() line.
Within the If() statement you open the dialog a second time!

Erik
 
A

Armin Zingler

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top