• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

VB.net image is not declared

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
Murray Brown
Asked:
Murray Brown
3 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
have you added the reference System.Drawing?
http://msdn.microsoft.com/en-us/library/4sahykhd%28v=vs.110%29.aspx
0
 
CodeCruiserCommented:
You would also need to add the

Imports System.Drawing

at the top of your code file after you add the reference.
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for the help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now