1.采用static变量
from1:
public partial class frmMain : Form
{
public static string name= "";
}
from2:
MessageBox.Show(Form1.name.Trim());
2.采用公共变量
from1:
public partial class frmMain : Form
{
//声明工位ID 为公共变量
public string terminalID = "";
//给变量赋值
terminalID = "q13bh01-bh12";
//单击‘行为’按钮的时候会给窗体传值
private void btnGroup_Click(object sender, EventArgs e)
{
frmGroup frmGro = new frmGroup();
//变量传值 ,注意顺序写在ShowDialog()方法之前
frmGro .stationID = this.terminalID;
frmGro .ShowDialog();
}
}
from2:
public partial class frmGroup : Form
{
//定义公共属性
public string stationID = "";
}