943,708 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 7088
  • C# RSS
Jul 7th, 2007
0

Help Needed in C# (picture viewer)

Expand Post »
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.

C# Syntax (Toggle Plain Text)
  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. }

Quote ...
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 ..
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
mytime19 is offline Offline
50 posts
since Dec 2006
Jul 7th, 2007
0

Re: Help Needed in C# (picture viewer)

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);}

Quote ...
'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.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
mytime19 is offline Offline
50 posts
since Dec 2006
Jul 8th, 2007
0

Re: Help Needed in C# (picture viewer)

post your current code for the entire file that is throwing the errors.

please wrap using

[ code="csharp" ]
[ /code ]

tags.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004
Jul 10th, 2007
0

Re: Help Needed in C# (picture viewer)

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.
Reputation Points: 26
Solved Threads: 11
Posting Whiz in Training
f1 fan is offline Offline
275 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: recusive method problem
Next Thread in C# Forum Timeline: how to include an NUnit fixture with an assembly





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC