Could someone explain why executing this method (in the constructor) throws a syntax error:
public partial class Form1 : Form
{
public Form1()
{
Load += YourPreparationHandler;
}
private void YourPreparationHandler(object sender, EventArgs e)
{
button22_Click(sender, e);
}
}
The name ‘button22_Click’ does not
exist in the current context
Usually in the constructor there is something like this:
Form classes are set up as partial classes. This is because in Visual Studio when you drag and drop components onto a form, behind the scenes VS is updateing the designer file with your updates.
So, you will have
Form1.cs
Form1.Designer.cs
and possibly
Form1.xx.resx (if you have globalization in place)
If you look at the designer file you will see something like this that Visual Studio is code generating:
I bet the designer file is missing, messed up, or InitializeComponent was removed by accident. In any case, the object (button_22) doesn’t exist or is not referenced so you will not be able to raise a click event on it.