| | |
Help Needed in C# (picture viewer)
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2006
Posts: 31
Reputation:
Solved Threads: 1
I have created a picture viewer in C# but it's giving 2 errors, i don't know how to deal with them. I'm at beginner level in C#. So please help me in this, I have written the code and errors below, you can look at that.
Can anyone help me in this code
Thanks a lot ..
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Myform : Form { private System.Windows.Forms.MenuItem menuFile; private System.Windows.Forms.MenuItem menuLoad; private System.Windows.Forms.MenuItem menuImage; private System.Windows.Forms.MenuItem menuExit; private System.Windows.Forms.MenuItem menuStretch; private System.Windows.Forms.MenuItem menuView; private PictureBox pboxPhoto; private void InitializeComponent() { this.menuFile = new System.Windows.Forms.MenuItem(); this.menuLoad = new System.Windows.Forms.MenuItem(); this.menuImage = new System.Windows.Forms.MenuItem(); this.menuExit = new System.Windows.Forms.MenuItem(); this.menuStretch = new System.Windows.Forms.MenuItem(); this.menuExit = new System.Windows.Forms.MenuItem(); this.menuView = new System.Windows.Forms.MenuItem(); this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuFile }); this.menuFile.Index = 0; this.menuFile.Text = "&File"; this.menuLoad.Index = 0; this.menuLoad.Shortcut = System.Windows.Forms.Shortcut.Ctrl; this.menuLoad.Text = "&Load"; this.menuExit.Index = 1; this.menuExit.Text = "&Exit"; menuView.Index = 1; menuView.Text = "&View"; } public Myform() { this.Text = "Picture viewer"; this.MinimumSize = new Size(200, 200); // Create and configure the PictureBox pboxPhoto = new PictureBox(); pboxPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; pboxPhoto.Width = this.Width; pboxPhoto.Height = this.Height; pboxPhoto.Left = (this.Width - pboxPhoto.Width) / 2; pboxPhoto.Top = (this.Height - pboxPhoto.Height) / 2; pboxPhoto.SizeMode = PictureBoxSizeMode.StretchImage; pboxPhoto.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; // Add our new controls to the Form this.Controls.Add(pboxPhoto); } private void Form1_Load(object sender, EventArgs e) { } protected void menuLoad_Click(object sender, System.EventArgs e) { menuLoad.Click += new System.EventHandler(this.menuLoad_Click); OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Photo"; dlg.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { try { pbxPhoto.Image = new Bitmap(dlg.OpenFile()); } catch (Exception ex) { MessageBox.Show("Unable to load file: " + ex.Message); } dlg.Dispose(); } } protected void menuExit_Click(object sender, System.EventArgs e) { this.Close(); } private PictureBoxSizeMode[] modeMenuArray = { PictureBoxSizeMode.StretchImage,PictureBoxSizeMode.Normal}; } }
•
•
•
•
Error Message 1: Type 'WindowsApplication1.Myform' already defines a member called 'InitializeComponent' with the same parameter types
Error message 2: The type 'WindowsApplication1.Myform' already contains a definition for 'menuFile'

Thanks a lot ..
•
•
Join Date: Dec 2006
Posts: 31
Reputation:
Solved Threads: 1
i tried to remove my errors by myself and finally i am at one last error as i replaced this code
by
and finally added this also in the myform class
Thanks, as i am trying to get it solve it very quickly as i can.
private PictureBoxSizeMode[] modeMenuArray =
{
PictureBoxSizeMode.StretchImage,PictureBoxSizeMode.Normal};
by
private PictureBoxSizeMode[] modeMenuArray=null;
and finally added this also in the myform class
protected override void Dispose(bool dispose){base.Dispose(dispose);}
•
•
•
•
'WindowsApplication1.Myform.Dispose(bool)' hides inherited member 'System.Windows.Forms.Form.Dispose(bool)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
•
•
Join Date: Jan 2006
Posts: 275
Reputation:
Solved Threads: 11
It seems you have copied (or used) a VS 2003 application in VS2005. There were some subtle changes when VS2005 was introduced which included Partial Classes.
Previously when creating a windows form in VS2003 you had 2 files created - the designer and the code file (plus resx but we will leave that as it didnt change). When you dropped a component on the VS2003 it added all the code to create that component in the InitialiseComponent() method in the cs code file. There used to be a region which was called "Windows Generated Code - Do not edit" where this was all done. But people used to mess in there and have their forms broken. So in VS2005 MS broke it out into a 3rd form (the designer file) and used Partial Classes (a partial class allows you to define a class in multiple files - which makes following your code much easier and I recommend you break all your classes down in this way).
You have copied the VS2003 c# code (myform.cs) (including the initialisecomponent() code) in your VS2005 c# code (myform.cs) and you already have a file (myform.designer.cs) with that in it. So the errors are because you have 2 InitialiseComponent methods (Which you are allowed - thats called overriding) but they have the same signature (ie same parameters - none in this case) which is not allowed in overriding.
The second error is the same as there are two identical instances of FileMenu trying to be created - one in your code and one in the designer code (both in the Initialise component).
If you are using VS2005 I think you can get rid of your InitialiseCompnent code (not the call to it in the constructor but the code itself) in your myform.cs file.
Previously when creating a windows form in VS2003 you had 2 files created - the designer and the code file (plus resx but we will leave that as it didnt change). When you dropped a component on the VS2003 it added all the code to create that component in the InitialiseComponent() method in the cs code file. There used to be a region which was called "Windows Generated Code - Do not edit" where this was all done. But people used to mess in there and have their forms broken. So in VS2005 MS broke it out into a 3rd form (the designer file) and used Partial Classes (a partial class allows you to define a class in multiple files - which makes following your code much easier and I recommend you break all your classes down in this way).
You have copied the VS2003 c# code (myform.cs) (including the initialisecomponent() code) in your VS2005 c# code (myform.cs) and you already have a file (myform.designer.cs) with that in it. So the errors are because you have 2 InitialiseComponent methods (Which you are allowed - thats called overriding) but they have the same signature (ie same parameters - none in this case) which is not allowed in overriding.
The second error is the same as there are two identical instances of FileMenu trying to be created - one in your code and one in the designer code (both in the Initialise component).
If you are using VS2005 I think you can get rid of your InitialiseCompnent code (not the call to it in the constructor but the code itself) in your myform.cs file.
![]() |
Similar Threads
- picture viewer taken over (Windows 95 / 98 / Me)
- TextMode (Command Line) Image Viewer? (Kernels and Modules)
- Disabling Win XP standard picture/fax viewer (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: recusive method problem
- Next Thread: how to include an NUnit fixture with an assembly
| Thread Tools | Search this Thread |
.net access activedirectory ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox connect control conversion cryptographyc#winformsencryption csharp custom database datagrid datagridview dataset datetime degrees development disabled displayingopenforms draganddrop drawing encryption enum event excel file foreach form format forms ftp function gdi+ httpwebrequest image index index-error input install java label list listbox mandelbrot math mathematics mouseclick mysql operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox serialization server setup sleep socket sql statistics stream string table text textbox thread time timer totaldays update user usercontrol validation visualstudio webbrowser windows winforms wpf xml





