bskiff Posted July 8, 2003 Posted July 8, 2003 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 Quote
*Experts* Bucky Posted July 8, 2003 *Experts* Posted July 8, 2003 You need to place an OpenFileDialog component on your form. Go to the form design view and create one from the toolbox. Quote "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 dynamic_sysop Posted July 9, 2003 Leaders Posted July 9, 2003 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 Quote
Mothra Posted July 9, 2003 Posted July 9, 2003 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. Quote Being smarter than you look is always better than looking smarter than you are.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.