开发者

Communication between Forms

开发者 https://www.devze.com 2023-02-04 12:08 出处:网络
Communication between form can be done in many ways usi开发者_开发知识库ng constructor using delegates etc in .netbut my question is how can i access a value that is entered into a child form from a p

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; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消