The code you have is problematic for other reasons (@CodyGray explains the reason you get a StackOverflowException ), but in general you can use the property to access without exposing the TextBox control itself; see this MSDN page for details, but for example:
namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { } public string FormText { get { return textBox1.Text; } set { textBox1.Text = value; } } } }
Then, to use this property:
public void p() { Form1 f = new Form1(); f.FormText = "change text"; }
EDIT:
Since there is at least one nitpick through comments and enough incentive for at least one person to find this point “excellent”, I also suggest a slightly different approach, still using the property ...
Suppose the goal is that you want to set text in p , we just return what we need:
public string p() { return "change text"; }
So, to:
myFormReferenceSomewhereNotInPrintClass.FormText = myPrintClassInstance.p();
Or do you want to get or use text in p :
public void p(string text) {
So, to:
myPrintClassInstance.p(myFormReferenceSomewhereNotInPrintClass.FormText);
source share