Step 8 of the first tutorial (http://msdn.microsoft.com/en-us/library/dd492131.aspx#footerLink)
will not compile
public partial class Form1 : Form
private void showButton_Click(object sender, EventArgs e)
// Show the Open File dialog. If the user clicks OK, load the
// picture that the user chose.
if (openFileDialog1.ShowDialog() == DialogResult.OK)
it always throws an error;
Error 1 'PictureViewer.Form1' does not contain a definition for 'openFileDialog1_FileOk' and no extension method 'openFileDialog1_FileOk' accepting a first argument of type 'PictureViewer.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Home User\my documents\visual studio 2010\Projects\PictureViewer\PictureViewer\Form1.Designer.cs 148 94 PictureViewer
This is as if I had not performed Step 7 where the OpenFileDialog is inserted, yet it has been and is visible and shows up in the Form1.Designer.cs;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Button showButton;
private System.Windows.Forms.Button clearButton;
private System.Windows.Forms.Button backgroundButton;
private System.Windows.Forms.Button closeButton;
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
There is a suppoed fix posted on tyhe tutorial community section, but it seems to be for VB, not C# and it is refuted by someone else.
I'm able to reproduce this by doubleclicking the openFileDialog1-Control in the designer and the deleting the automatically generated mehtod-stub-code in the code-view.
To get rid of this error, you'll have to edit the file "Form1.Designer.cs". In the Project-Explorer doubleclick the Form1.Designer.cs-file (if not shown in the Project-Explorer, click the small Triangle in front of "Form1.cs").
In the now opened code-view of that file, search for the line: (it's in the method: InitializeComponent, maybe you'll have to click one of the small "+" signs at the beginning of a #region generated by the WinFormsDesigner)
this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);
and remove it. This will remove the handler for that event, and the program should run now.
- Marked as answer by Nancy Shao Thursday, August 26, 2010 8:46 AM