Reputation: 4127
Communication between form can be done in many ways using constructor using delegates etc in .net but my question is how can i access a value that is entered into a child form from a parent form or can a two way communication is possible between windows forms.
Upvotes: 0
Views: 740
Reputation: 40756
Provide the values of the child form as properties that can be accessed from the parent form.
E.g.
using ( var form = new ChildForm() )
{
form.SomeValue = "abc";
if ( form.ShowDialog(this) == DialogResult.OK )
{
var x = form.SomeValue;
}
}
Use this block in your parent form to pass values to and from the child form.
In the child form, the SomeValue
property can map to e.g. a TextBox
:
public string SomeValue
{
get { return MyTextBox.Text.Trim(); }
set { MyTextBox.Text = value; }
}
Upvotes: 7