Help Needed in C# (picture viewer)

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 31
Reputation: mytime19 is an unknown quantity at this point 
Solved Threads: 1
mytime19 mytime19 is offline Offline
Light Poster

Help Needed in C# (picture viewer)

 
0
  #1
Jul 7th, 2007
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.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace WindowsApplication1
  10. {
  11. public partial class Myform : Form
  12. {
  13. private System.Windows.Forms.MenuItem menuFile;
  14. private System.Windows.Forms.MenuItem menuLoad;
  15. private System.Windows.Forms.MenuItem menuImage;
  16. private System.Windows.Forms.MenuItem menuExit;
  17. private System.Windows.Forms.MenuItem menuStretch;
  18. private System.Windows.Forms.MenuItem menuView;
  19.  
  20. private PictureBox pboxPhoto;
  21.  
  22. private void InitializeComponent()
  23. {
  24. this.menuFile = new System.Windows.Forms.MenuItem();
  25. this.menuLoad = new System.Windows.Forms.MenuItem();
  26. this.menuImage = new System.Windows.Forms.MenuItem();
  27. this.menuExit = new System.Windows.Forms.MenuItem();
  28. this.menuStretch = new System.Windows.Forms.MenuItem();
  29. this.menuExit = new System.Windows.Forms.MenuItem();
  30. this.menuView = new System.Windows.Forms.MenuItem();
  31.  
  32. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuFile });
  33. this.menuFile.Index = 0;
  34. this.menuFile.Text = "&File";
  35. this.menuLoad.Index = 0;
  36. this.menuLoad.Shortcut = System.Windows.Forms.Shortcut.Ctrl;
  37. this.menuLoad.Text = "&Load";
  38. this.menuExit.Index = 1;
  39. this.menuExit.Text = "&Exit";
  40.  
  41. menuView.Index = 1;
  42. menuView.Text = "&View";
  43.  
  44. }
  45.  
  46. public Myform()
  47. {
  48. this.Text = "Picture viewer";
  49. this.MinimumSize = new Size(200, 200);
  50.  
  51.  
  52.  
  53. // Create and configure the PictureBox
  54. pboxPhoto = new PictureBox();
  55. pboxPhoto.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  56. pboxPhoto.Width = this.Width;
  57. pboxPhoto.Height = this.Height;
  58. pboxPhoto.Left = (this.Width - pboxPhoto.Width) / 2;
  59. pboxPhoto.Top = (this.Height - pboxPhoto.Height) / 2;
  60. pboxPhoto.SizeMode = PictureBoxSizeMode.StretchImage;
  61. pboxPhoto.Anchor = AnchorStyles.Top | AnchorStyles.Bottom
  62. | AnchorStyles.Left | AnchorStyles.Right;
  63. // Add our new controls to the Form
  64. this.Controls.Add(pboxPhoto);
  65.  
  66.  
  67. }
  68.  
  69. private void Form1_Load(object sender, EventArgs e)
  70. {
  71.  
  72. }
  73.  
  74. protected void menuLoad_Click(object sender, System.EventArgs e)
  75. {
  76. menuLoad.Click += new System.EventHandler(this.menuLoad_Click);
  77.  
  78. OpenFileDialog dlg = new OpenFileDialog();
  79. dlg.Title = "Open Photo";
  80. dlg.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
  81. if (dlg.ShowDialog() == DialogResult.OK)
  82. {
  83. try
  84. {
  85. pbxPhoto.Image = new Bitmap(dlg.OpenFile());
  86. }
  87. catch (Exception ex)
  88. {
  89. MessageBox.Show("Unable to load file: " + ex.Message);
  90. }
  91.  
  92. dlg.Dispose();
  93. }
  94. }
  95.  
  96. protected void menuExit_Click(object sender, System.EventArgs e)
  97. {
  98. this.Close();
  99. }
  100. private PictureBoxSizeMode[] modeMenuArray =
  101. {
  102. PictureBoxSizeMode.StretchImage,PictureBoxSizeMode.Normal};
  103. }
  104. }

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 ..
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 31
Reputation: mytime19 is an unknown quantity at this point 
Solved Threads: 1
mytime19 mytime19 is offline Offline
Light Poster

Re: Help Needed in C# (picture viewer)

 
0
  #2
Jul 7th, 2007
i tried to remove my errors by myself and finally i am at one last error as i replaced this code

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.
Thanks, as i am trying to get it solve it very quickly as i can.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: Help Needed in C# (picture viewer)

 
0
  #3
Jul 8th, 2007
post your current code for the entire file that is throwing the errors.

please wrap using

[ code="csharp" ]
[ /code ]

tags.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 275
Reputation: f1 fan is an unknown quantity at this point 
Solved Threads: 11
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Help Needed in C# (picture viewer)

 
0
  #4
Jul 10th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC