This seems to be coming up in a LOT of posts at the moment so i figured i would put it into a handy code snippet to save us keep typing it.
To access controls on a form you need to have a reference to the current instance of that form.
The easiest way to do this is to pass a reference to the "parent" form into the "child" form when you instantiate it.
By passing a reference to the parent into the child, the child can then access all the public members of the parent through that reference.
A point of note; i have used a read only property to access the text property of the textbox. Some people suggest making the control public but this violates the OO design principles of Encapsulation.
By only allowing access to internal members via properties you can a) control and validate the data passed in and out of the class and b) alter the internal workings of the class without impacting on external classes which access its members.
Edited 6 Years Ago by Geekitygeek: n/a