Send values from one form to another form

2018-12-31 02:44发布

I want to pass values between two Forms (c#). How can I do it?

I have two forms: Form1 and Form2.

Form1 contains one button. When I click on that button, Form2 should open and Form1 should be in inactive mode (i.e not selectable).

Form2 contains one text box and one submit button. When I type any message in Form2's text box and click the submit button, the Form2 should close and Form1 should highlight with the submitted value.

How can i do it? Can somebody help me to do this with a simple example.

19条回答
残风、尘缘若梦
2楼-- · 2018-12-31 03:43

Simple get the value with:

var form1 = new Form1();
string sample = form1.examplestring;

To set the value :

var form1 = new Form1();
form1.examplestring = example;

but check the string to be "public string"

public string example = "test";
查看更多
登录 后发表回答