You excluded the method InitializeComponent()
which should be called in the form constructor. This method is declared in the other part of the class (note that the class has the modifier partial
), it’s probably in an archive Form1.Designer.cs
.
Basically the method InitializeComponent()
instancia and creates all the components in your form, so this NullReferenceException
is popping - the variable button1
(as all other components) were not instantiated.
Your builder should stay like this:
public Form1()
{
InitializeComponent();
button1.Click += Button1_Click;
}
Although it has nothing to do with the error, it is important to say that you do not need to declare your variables as decimal
, you can declare them directly as int
. This won’t cause big problems, but I don’t see the point to do it. If you want to use an integer create a variable int
.
In which line? Only with this excerpt can not identify where the problem is. This error is symptom of problem elsewhere. By the way, you’re not in trouble at Visual Studio, understand: http://answall.com/a/101703/101
– Maniero