Your textbox is a member of the Form1
class, access to it is possible inside the member functions of the Form1
class,
Form1.cs
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void DoSomeStuffWithTextBox() { textBox1.Text = "some text"; } } }
And on the class object through a point from other classes - is impossible, since the access level of textboxes inserted through the form designer is private
Form1.Designer.cs
namespace WindowsFormsApplication1 { partial class Form1 { ................................ private System.Windows.Forms.TextBox textBox1; } }
Although, you can manually change the access level for textBox1
to public
in this file;) <crutch />. And, although the file is generated automatically, if you change the form, your editing will be saved (if you do not delete textBox1
from the form, of course).
It is best to make a public method (or property) in the form that returns a reference to textBox1
.
namespace WindowsFormsApplication1 { public partial class Form1 : Form { ..................... public TextBox getTextBox() { return textBox1; } } }