You're attempting to access a static property Controls
on the Main
class, but no such property exists. It wouldn't make sense either as controls belong to an instance of your form class.
Your entire Painter
class is superfluous. Just add your controls in your Form's constructor.
public class Main : Form
{
public Form()
{
SuspendLayout();
var label1 = new Label();
var txtbx1 = new TextBox();
label1.UseMnemonic = true;
label1.Text = "First &Name:";
label1.Location = new Point(15, 15);
label1.BackColor = Color.Pink;
label1.ForeColor = Color.Maroon;
label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
label1.Size = new Size(label1.PreferredWidth, label1.PreferredHeight + 2);
txtbx1.Text = "Enter Your Name";
txtbx1.Location = new Point(15 + label1.PreferredWidth + 5, 15);
txtbx1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
txtbx1.BackColor = Color.LightGray;
txtbx1.ForeColor = Color.Maroon;
txtbx1.Size = new Size(90, 20);
Controls.Add(label1);
Controls.Add(txtbx1);
ResumeLayout();
}
}
This is where that code belongs anyway. Your form should be responsible for its layout, not some other class. This is how the designer would have done it.
A partial class would have been created with a method named InitializeComponent
which creates and lays out the controls. It would have been called from the constructor.