Solved

VB.net image is not declared

Posted on 2014-07-22
4
285 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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