Moving text from one form to another form

  • Thread starter Thread starter Aaron
  • Start date Start date
A

Aaron

Hello,

I have a textbox(txtFines) on one form(frmMain) that needs to have the text
moved too a different form(frmFines) in a textbox(txtFineList) on
btnDone_Click function.

I know how to transfer textbox text too a different textbox on the same form
but not on too a different form.

Aaron
 
Hi Aaron,

frmMain needs to have a reference to frmFines.
How do you create frmMain, frmFines?

If frmFines is created from frmMain simply store the reference to it as a class variable.

FormFines frmFines;

....
....

frmFines = new FormFines();

....
....

Create a property in frmFines that exposes txtFineList.Text

public string FineText
{
get
{
return txtFineList.Text;
}
set
{
txtFineList.Text = value;
}
}

then when you need to (in the button click event), from frmMain

frmFines.FineText = "Text I want in the textbox";
 
There are many methods for doing this.

You could create a public string property in frmFines and then set it in
frmMain.
Or you could have a public method in frmFines, which would accept the text.
Or, you could have a delegate accepting a string which would invoke a method
in frmFines.
 
Back
Top