I’m starting with C# and I went through this tutorial on how to create a simple picture viewer:
http://msdn.microsoft.com/en-us/library/dd492135.aspx
You create it with a few buttons, the picture viewing area, and a checkbox.
When I created the form and added some buttons, I was able to run the debugger, see the application, and click on buttons that did nothing.
It seems that to create a method for an event such as a button click you can double-click the button in the form design as a shortcut.
However, I can’t seem to remove a method and run it. For example, I created private void pictureBox1_Click. However, I don’t need the form to do anything when I click on the picture. I wanted to delete that method. However, I then get an error that states:
“‘PictureViewer.Form1’ does not contain a definition for ‘pictureBox1_Click’ and no extension method ‘pictureBox1_Click’ accepting a first argument of type ‘PictureViewer.Form1’ could be found (are you missing a using directive or an assembly reference?)”
What am I missing? Is there something else created besides that one method when I doubleclick the pictureBox? Not that it’s particularly bothersome, but it’d be weird to have to leave empty methods in the code for everything you accidentally created.
On a quick second question, where is the code for the controls and containers I add? I would think there’d be a place besides the properties window to set various properties.
Thank you for your help!
Expand the Node for your “Form1” in the Solution Explorer and doubleclick on the Designer.cs (Form1.Designer.cs). I think there is still a reference to the picturebox1 click event. you need to remove this.
Anyway, the Designer.cs holds all information about your controls/containers that you add to your form, but you can still overwrite this by create new values in the regular code behind of ‘form1’.