The first thing to note is that you really shouldn't be trying at all.
If you expose your form controls directly (by making them
public
) then you lock the design of your form - you can no longer change the way the form works without potentially affecting any other code which may use it. This is not a good idea, and is why all controls are
private
by default.
Instead, you should provide public properties which access the information, and let external code use them. You can then change the way your form works when you need to, and provided the properties still return the same values, no external code is affected:
public string StudentFirstName
{
get { return txtStudentFirstName.Text; }
set { txtStudentFirstName.Text = value; }
}
The reason you are getting an exception is probably that you are trying to construct a form within an instance of itself - Form1 is the default name for the main form in Visual Studio and if you haven't changed it then you are trying to construct Form1 inside Form1, which means that it tries to build another Form1 inside that, which... and so on util you run out of memory and it throws an exception.