C# 将数据从一个窗体获取到另一个窗体

C# 将数据从一个窗体获取到另一个窗体,c#,winforms,forms,C#,Winforms,Forms,我有一个包含两个表单的项目,表单1和表单2。Form1创建Form2的新实例。在表格2中,我为计时器输入一个数字,然后在表格1中,我想拉那个数字,设置并启动计时器 但是,我无法在运行时将该数字从Form2拉入Form1。有人知道这是否可行吗。谢谢你的帮助 看一看 对话结果 其思想是这样打开表单: Form myForm = new Form(); if(myForm.ShowDialog() == DialogResult.OK) { // Access the value; C

我有一个包含两个表单的项目,表单1和表单2。Form1创建Form2的新实例。在表格2中,我为计时器输入一个数字,然后在表格1中,我想拉那个数字,设置并启动计时器

但是,我无法在运行时将该数字从Form2拉入Form1。有人知道这是否可行吗。谢谢你的帮助

看一看

对话结果

其思想是这样打开表单:

Form myForm = new Form();
if(myForm.ShowDialog() == DialogResult.OK)
{
    // Access the value;
    Console.out.WriteLine(myForm.TheValue);
}
在我的表格里,你会有类似的东西

private string sTheValue = null;
public string TheValue
{
    get { return this.sTheValue; }
}

private void Button_Click(object sender, EventArgs e)
{
    this.sTheValue = "Hello World !";
    this.DialogResult = DialogResult.OK;
    this.Close();
}
在form2的其他地方

this.Form1.No = int.Parse(txt.Text); // No is a property in Form1 which is listening for changes...

使其成为
Form2
中的公共属性,可从
Form1
this.Form1.No = int.Parse(txt.Text); // No is a property in Form1 which is listening for changes...