Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm new here. My name is Bill and I might be bugging you guy regularly now! I have been developing applications for about 12 years now. I am now learning VB.net. It is very similar to the Powerbuilder that I've been using for the past 7 years. I am working my way though the tutorials in the book 'Visual Basic.Net Step by Step'. I'm still in the beginning of the book. I am add script to a menu clicked event. I copied the following code right out of the book:

 

OpenFileDialog1.Filter = "Bitmaps (*.bmp)|*.bmp"

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

PictureBox1.Image = System.Drawing.Image.FromFile _

(OpenFileDialog1.FileName)

mnuCloseItem.Enabled = True

End If

 

I get an undeclared variable error on 'OpenFileDialog1'. When I look at they solution in the book, it has the same code and no error. Can someone point me in the right direction to track this down? I don't want to just copy the books solution without understanding.

 

Thanks,

Bill

  • *Experts*
Posted

You need to place an OpenFileDialog component on your form.

Go to the form design view and create one from the toolbox.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • Leaders
Posted

you could also do it without phisically putting an openfile dialog on the form , like this :

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim od As New OpenFileDialog()

       With od
           .Filter = ("Bitmaps (*.bmp)|*.bmp")
           .ShowDialog()
       End With

       If Not od.ShowDialog = DialogResult.Cancel Then
           Dim im As Image
           im = im.FromFile(od.FileName)
           PictureBox1.Image = im
       End If

   End Sub

Posted

I'm not sure if anyone else would have this problem but, when I ran the code:

 

If Not od.ShowDialog = DialogResult.Cancel Then
    '...
End If

 

It popped up the open file dialog a second time. I found that if I change the line to this:

 

If Not od.ShowDialog.Cancel Then
    '...
End If

 

it worked just fine.

Being smarter than you look is always better than looking smarter than you are.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...