Using control from a separate class in C#
Posted
by
DazSlayer
on Stack Overflow
See other posts from Stack Overflow
or by DazSlayer
Published on 2011-01-12T05:44:27Z
Indexed on
2011/01/12
5:54 UTC
Read the original article
Hit count: 225
I have a program that dynamically creates controls when it starts, it works just fine when the code to do this is in the class of the actual form. I tried moving the code to a separate class and found that I could not use Controls.Add(). How can I add controls to the Form from a separate class? This is what I have so far:
TextBox txtbx = new TextBox();
txtbx.Text = "asd" + x.ToString();
txtbx.Name = "txtbx" + x.ToString();
txtbx.Location = new Point(10, (20 * x));
txtbx.Height = 20;
txtbx.Width = 50;
Controls.Add(txtbx);
Error 1 The name 'Controls' does not exist in the current context
© Stack Overflow or respective owner