Solved

VB.net image is not declared

Posted on 2014-07-22
4
274 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:murbro
4 Comments
 
LVL 142

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:murbro
ID: 40213993
Thanks very much for the help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now