?
Solved

VB.net image is not declared

Posted on 2014-07-22
4
Medium Priority
?
322 Views
Last Modified: 2014-07-23
Hi. In the following code I get the error "image is not declared" at the line marked 'ERROR


    Dim result As DialogResult = OpenFileDialog1.ShowDialog
        If result = Windows.Forms.DialogResult.OK Then
            If (OpenFileDialog1.FileName IsNot Nothing) Or (OpenFileDialog1.FileName <> String.Empty) Then

                PictureBox1.BackgroundImage = Image.FromFile(OpenFileDialog1.FileName) 'ERROR
                PictureBox1.BackgroundImageLayout = ImageLayout.Zoom
                Label1.Visible = True
                TextBox1.Visible = True
                Label1.Text = "Name"
                TextBox1.Clear()

            End If
        End If
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 668 total points
ID: 40211260
have you added the reference System.Drawing?
http://msdn.microsoft.com/en-us/library/4sahykhd%28v=vs.110%29.aspx
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 668 total points
ID: 40211556
You would also need to add the

Imports System.Drawing

at the top of your code file after you add the reference.
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 664 total points
ID: 40213523
The reference is certainly set, otherwise the Form itself would not compile and would not show in the Form Designer.

Imports would work and would be more interesting if you often call stuff in System.Drawing, but you can also define the namespace right in the line of code.

PictureBox1.BackgroundImage = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)

And since System is always assumed by default in a .NET application (it is imported at the project level), the following would also work in most situations:

PictureBox1.BackgroundImage = Drawing.Image.FromFile(OpenFileDialog1.FileName)
0
 

Author Closing Comment

by:Murray Brown
ID: 40213993
Thanks very much for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question