Communication between Forms
Communication between form can be done in many ways usi开发者_开发知识库ng 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.
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; }
}
精彩评论