Open Dialog Appears again if you press cancel

ironfistchamp

Active member
Joined
Dec 9, 2005
Messages
29
Programming Experience
Beginner
I have some code to stop my program throwing errors when you press cancel on the open and save dialog boxes.

Looks like this

openFD.InitialDirectory = "C:\"
openFD.Filter = "Jpeg Files|*.jpg"
openFD.ShowDialog()
Dim DidWork As Integer = openFD.ShowDialog()
If DidWork = Windows.Forms.DialogResult.OK Then
pbox.Visible = True
rtbMain.Visible = False
pbox.ImageLocation = openFD.FileName
End If

When you press cancel the dialog box opens again. If you press cancel for the second time it goes. if this code is left out and just tell it how to open it throws up errors. can someone help stop it opening a second time?

Thanks

Ironfistchamp

 
ironfistchamp said:
I have some code to stop my program throwing errors when you press cancel on the open and save dialog boxes.

Looks like this

openFD.InitialDirectory = "C:\"
openFD.Filter = "Jpeg Files|*.jpg"
openFD.ShowDialog()
Dim DidWork As Integer = openFD.ShowDialog()
If DidWork = Windows.Forms.DialogResult.OK Then
pbox.Visible = True
rtbMain.Visible = False
pbox.ImageLocation = openFD.FileName
End If

When you press cancel the dialog box opens again. If you press cancel for the second time it goes. if this code is left out and just tell it how to open it throws up errors. can someone help stop it opening a second time?

Thanks

Ironfistchamp

you'r calling the ShowDialog twice, so no matter what the user does it'll appear twice
here's an idea on how to fix this:
VB.NET:
With openFD
[FONT=Lucida Console]  .InitialDirectory = "C:\"
  .Filter = "Jpeg Files|*.jpg"
End With
If [/FONT][FONT=Lucida Console]openFD.ShowDialog() <> DialogResult.Cancel[/FONT][FONT=Lucida Console] Then
  pbox.Visible = True
  rtbMain.Visible = False
  pbox.ImageLocation = openFD.FileName
End If[/FONT]
Notice that i it's checking for a NotEqualTo Cancel which prevents any problems that can occur if you only check for DialogResult.Ok
 
Back
Top