I'm following this tutorial on winforms, and so far the tutorial is coding the form without using the toolbox. I believe it'll introduce the toolbox in more depth shortly.
Following the tutorial, I've made a partial class in the following two pieces of code:
First file:
using System;
using System.Windows.Forms;
public class Numeric : System.Windows.Forms.TextBox
{
public Numeric()
{
}
}
public partial class Exercise
{
private Numeric txtbox;
System.ComponentModel.Container components;
}
Second file:
using System;
using System.Windows.Forms;
public partial class Exercise : Form
{
private void InitializeComponent()
{
txtbox = new Numeric();
Controls.Add(txtbox);
}
public Exercise()
{
InitializeComponent();
}
}
public class program
{
public static int Main()
{
Application.Run(new Exercise());
return 0;
}
}
When I run the code with F5, everything looks fine: The form pops up with the textbox.
But for some reason, when I right-click on the second file and choose "View Designer", I get an error which says "The variable 'txtbox' is either undeclared or was never assigned". I can choose to "Ignore and Continue", which leads me to a form with no textbox on it.
Why does this occur? I know some of you think I should just use the toolbox, and it's probably the most sensible thing to do, but I would still like to understand why this happens.