C#的不同窗口传值
1.通过构造函数传值
this.Hide();
Form1 form01 = new Form1(textBox2.Text);
form01.Show();
public Form1(string aaa)
{InitializeComponent();label12.Text = aaa;
}
2.全局类传值
namespace WindowsFormsApp1
{public class Global{private static Global _Instance=null;public static Global Instance{get { if (_Instance == null)_Instance = new Global();return _Instance;}}public string name = "123";}
}
this.Hide();
Form1 form01 = new Form1();
Global.Instance.name = textBox2.Text;
form01.Show();
private void Form1_Load(object sender, EventArgs e){label3.Text = DateTime.Now.ToString("yyyy:MM:dd:HH:mm:ss.ff");this.Text = "zijishengchang ";label12.Text = Global.Instance.name;}