473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

New to C#can run first program

Hi all
I would appreciate some help with a program I have written from the Sams
teach your self c# book.
I have checked my code several times and even rewritten it.

when I compile (Sharp develop) I get the following error :

------ Build started: Project: Pic view 2 Configuration: Debug ------
Performing main compilation...

c:\Documents and Settings\Chris\My Documents\SharpDevelop Projects\Pic view
2\fclsViewer.cs(106,28): error CS0246: The type or namespace name 'Image'
could not be found (are you missing a using directive or an assembly
reference?)
Build complete -- 1 errors, 0 warnings

The code I have written is below. Any help would be greatly appreciated.

Thanks

Chris

.................................................. .................................................. .................................................. .................................................. ..............................................
/*
* Created by Sharp.
* User: Chris
* Date: 16/08/2004
* Time: 15:50
*
* To change this template use Tools | Options | Coding | Edit Standard
Headers.
*/
using System;
using System.Windows.Forms;
namespace DefaultNamespace
{
/// <summary>
/// Description of fclsViewer.
/// </summary>
public class fclsViewer : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnSelectPicture;
private System.Windows.Forms.Button btnQuit;
private System.Windows.Forms.PictureBox picShowPicture;
private System.Windows.Forms.OpenFileDialog ofdSelectPicture;
public fclsViewer()
{
//
// The InitializeComponent() call is required for Windows Forms designer
support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new fclsViewer());
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The
Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(fclsViewer ));
this.ofdSelectPicture = new System.Windows.Forms.OpenFileDialog();
this.picShowPicture = new System.Windows.Forms.PictureBox();
this.btnQuit = new System.Windows.Forms.Button();
this.btnSelectPicture = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// ofdSelectPicture
//
this.ofdSelectPicture.Filter = "Windows Bitmaps|*.Bmp|JPEG Files|*.jpg";
this.ofdSelectPicture.Title = "Select Picture";
//
// picShowPicture
//
this.picShowPicture.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.picShowPicture.Location = new System.Drawing.Point(8, 8);
this.picShowPicture.Name = "picShowPicture";
this.picShowPicture.Size = new System.Drawing.Size(282, 275);
this.picShowPicture.TabIndex = 2;
this.picShowPicture.TabStop = false;
//
// btnQuit
//
this.btnQuit.Location = new System.Drawing.Point(301, 40);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(85, 23);
this.btnQuit.TabIndex = 1;
this.btnQuit.Text = "Quit";
this.btnQuit.Click += new System.EventHandler(this.BtnQuitClick);
//
// btnSelectPicture
//
this.btnSelectPicture.Location = new System.Drawing.Point(301, 10);
this.btnSelectPicture.Name = "btnSelectPicture";
this.btnSelectPicture.Size = new System.Drawing.Size(85, 23);
this.btnSelectPicture.TabIndex = 0;
this.btnSelectPicture.Text = "Select Picture";
this.btnSelectPicture.Click += new
System.EventHandler(this.BtnSelectPictureClick);
//
// fclsViewer
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(392, 291);
this.Controls.Add(this.picShowPicture);
this.Controls.Add(this.btnQuit);
this.Controls.Add(this.btnSelectPicture);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.Name = "fclsViewer";
this.Text = "Picture Viewer";
this.ResumeLayout(false);
}
#endregion
void BtnSelectPictureClick(object sender, System.EventArgs e)
{
//Show the open files dialog box.
if (ofdSelectPicture.ShowDialog()==DialogResult.OK)
{
//Load the Pitcure into the Picture box
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName);
this.Text=String.Concat("picture Viewer ("+ ofdSelectPicture.FileName
+")"); }
}
void BtnQuitClick(object sender, System.EventArgs e)
{
this.Close();
}
}
}
Nov 16 '05 #1
5 2316
Dive into the MSDN and find out in which namespace the "Image" class lives.

Add "using <namespace>;" to make sure C# compiler finds it...
Currently it isn't in your code...

- Joris
Nov 16 '05 #2
> //Show the open files dialog box.
if (ofdSelectPicture.ShowDialog()==DialogResult.OK)
{
//Load the Pitcure into the Picture box
This line:
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName);
is stopping the show.

'Image' is a class from System.Drawing. If that namespace is referenced in
your
project, you can try fully-qualifying it such as:
picShowPicture.Image =
System.Drawing.Image.FromFile(ofdSelectPicture.Fil eName);
Which would have to be done anywhere you need to use the Image class, so the
better alternative would be just to add a 'using System.Drawing' at the
beginning
of the code. If, however, you are not referencing System.Drawing in the
project,
the code will not work at all, so the first step is to reference the
namespace if it is
not already.
this.Text=String.Concat("picture Viewer ("+ ofdSelectPicture.FileName
+")"); }
}
void BtnQuitClick(object sender, System.EventArgs e)
{
this.Close();
}
}
}

Nov 16 '05 #3
Chris <Gi***********@hotmail.com> wrote:
I would appreciate some help with a program I have written from the Sams
teach your self c# book.
I have checked my code several times and even rewritten it.
when I compile (Sharp develop) I get the following error :


<snip>

The Image class is in the System.Drawing namespace, so you need to
either specify System.Drawing.Image.FromFile or put using
System.Drawing; in the using statements.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
hi,

i think it's this bit that causing the problem

//Load the Pitcure into the Picture box
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName);

you need to add a reference to the System.drawing
namespace.(System.Drawing.dll)

HTH
Sam
"Chris" <Gi***********@hotmail.com> wrote in message
news:wu**************@newsfe6-gui.ntli.net...
Hi all
I would appreciate some help with a program I have written from the Sams
teach your self c# book.
I have checked my code several times and even rewritten it.

when I compile (Sharp develop) I get the following error :

------ Build started: Project: Pic view 2 Configuration: Debug ------
Performing main compilation...

c:\Documents and Settings\Chris\My Documents\SharpDevelop Projects\Pic view 2\fclsViewer.cs(106,28): error CS0246: The type or namespace name 'Image'
could not be found (are you missing a using directive or an assembly
reference?)
Build complete -- 1 errors, 0 warnings

The code I have written is below. Any help would be greatly appreciated.

Thanks

Chris

.................................................. ...........................
.................................................. ...........................
.................................................. ...........................
.................. /*
* Created by Sharp.
* User: Chris
* Date: 16/08/2004
* Time: 15:50
*
* To change this template use Tools | Options | Coding | Edit Standard
Headers.
*/
using System;
using System.Windows.Forms;
namespace DefaultNamespace
{
/// <summary>
/// Description of fclsViewer.
/// </summary>
public class fclsViewer : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnSelectPicture;
private System.Windows.Forms.Button btnQuit;
private System.Windows.Forms.PictureBox picShowPicture;
private System.Windows.Forms.OpenFileDialog ofdSelectPicture;
public fclsViewer()
{
//
// The InitializeComponent() call is required for Windows Forms designer
support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
[STAThread]
public static void Main(string[] args)
{
Application.Run(new fclsViewer());
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The
Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(fclsViewer ));
this.ofdSelectPicture = new System.Windows.Forms.OpenFileDialog();
this.picShowPicture = new System.Windows.Forms.PictureBox();
this.btnQuit = new System.Windows.Forms.Button();
this.btnSelectPicture = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// ofdSelectPicture
//
this.ofdSelectPicture.Filter = "Windows Bitmaps|*.Bmp|JPEG Files|*.jpg";
this.ofdSelectPicture.Title = "Select Picture";
//
// picShowPicture
//
this.picShowPicture.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.picShowPicture.Location = new System.Drawing.Point(8, 8);
this.picShowPicture.Name = "picShowPicture";
this.picShowPicture.Size = new System.Drawing.Size(282, 275);
this.picShowPicture.TabIndex = 2;
this.picShowPicture.TabStop = false;
//
// btnQuit
//
this.btnQuit.Location = new System.Drawing.Point(301, 40);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(85, 23);
this.btnQuit.TabIndex = 1;
this.btnQuit.Text = "Quit";
this.btnQuit.Click += new System.EventHandler(this.BtnQuitClick);
//
// btnSelectPicture
//
this.btnSelectPicture.Location = new System.Drawing.Point(301, 10);
this.btnSelectPicture.Name = "btnSelectPicture";
this.btnSelectPicture.Size = new System.Drawing.Size(85, 23);
this.btnSelectPicture.TabIndex = 0;
this.btnSelectPicture.Text = "Select Picture";
this.btnSelectPicture.Click += new
System.EventHandler(this.BtnSelectPictureClick);
//
// fclsViewer
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(392, 291);
this.Controls.Add(this.picShowPicture);
this.Controls.Add(this.btnQuit);
this.Controls.Add(this.btnSelectPicture);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.Name = "fclsViewer";
this.Text = "Picture Viewer";
this.ResumeLayout(false);
}
#endregion
void BtnSelectPictureClick(object sender, System.EventArgs e)
{
//Show the open files dialog box.
if (ofdSelectPicture.ShowDialog()==DialogResult.OK)
{
//Load the Pitcure into the Picture box
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName);
this.Text=String.Concat("picture Viewer ("+ ofdSelectPicture.FileName
+")"); }
}
void BtnQuitClick(object sender, System.EventArgs e)
{
this.Close();
}
}
}

Nov 16 '05 #5
Thanks for the help I needed to add the 'using System.Drawing' line in the
file.
The book doesn't tell you that but when you look at the downloadable source
files its there.

"Gary Morris" <gw*******@hotpop.com> wrote in message
news:O8**************@TK2MSFTNGP11.phx.gbl...
//Show the open files dialog box.
if (ofdSelectPicture.ShowDialog()==DialogResult.OK)
{
//Load the Pitcure into the Picture box


This line:
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName);
is stopping the show.

'Image' is a class from System.Drawing. If that namespace is referenced in
your
project, you can try fully-qualifying it such as:
picShowPicture.Image =
System.Drawing.Image.FromFile(ofdSelectPicture.Fil eName);
Which would have to be done anywhere you need to use the Image class, so
the
better alternative would be just to add a 'using System.Drawing' at the
beginning
of the code. If, however, you are not referencing System.Drawing in the
project,
the code will not work at all, so the first step is to reference the
namespace if it is
not already.
this.Text=String.Concat("picture Viewer ("+ ofdSelectPicture.FileName
+")"); }
}
void BtnQuitClick(object sender, System.EventArgs e)
{
this.Close();
}
}
}


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ron Adam | last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone here for a great programming language. Below is my first Python program (not my first program) and I'd apreciate any...
27
by: hokiegal99 | last post by:
Hi Guys, This is my first C program. I started programming in Python. Please look over this source and let me know if I'm doing anything wrong. I want to start out right with C, so if you see...
18
by: strchild | last post by:
Hey Guys, I've been perusing the newsgroup here for some time now, and going through my ever so non-helpful book, Microsoft Visual Basic .NET Step by Step Version 2003, over and over, and I feel...
26
by: mwt | last post by:
Hello. Today I wrote my first program in C. It adds up the elements in an array. I am just beginning to learn this language. Any tips or pointers about better ways to write/structure/format/etc....
5
by: Jonathan | last post by:
Hi-- I have the following code: #include <stdio.h> char a,b; int main()
109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
3
by: cs | last post by:
Hi, I'm new to C and would appreciate any feedback on the following program, asplit, which splits a file into 2 new files, putting a certain number of lines in the first file, and all the rest...
9
by: xiao | last post by:
It always dumped when I tried to run it... But it compiles OK. What I want to do is to do a test: Read information from a .dat file and then write it to another file. The original DAT file is...
4
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.