Solved

VB.net image is not declared

Posted on 2014-07-22
4
309 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 167 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 167 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 166 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

Independent Software Vendors: 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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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