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.
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'
Can anyone help me in this code:(
Thanks a lot ..