变量不会存储文本框值
Variable wont store the textbox value
我想做的是将变量从 form2 转移到 form5 并使用这些变量替换 form5 上已有的标签
所以我尝试的是
//this is form 2
public string name;
public string surname;
name = textBox1.Text;
surname = textBox2.Text;
this.Hide();
var form3 = new Form3();
form3.Show();
//this is form 5
private void Form5_Load(object sender, EventArgs e)
{
Form1 form1 = new Form1();
label1.Text = form1.name;
label2.Text = form1.surname;
}
表格 5 上标签的默认值为“Placheholder”,由于某些原因,它们不会更改为变量,这是什么问题
在 Form1 上,将字符串设置为
public static string name;
public static string surname;
然后,在Form2
string newSurname;
string newName;
public Form2()
{
InitializeComponent();
newSurname = Form1.surname;
newName = Form1.name;
}
我想做的是将变量从 form2 转移到 form5 并使用这些变量替换 form5 上已有的标签
所以我尝试的是
//this is form 2
public string name;
public string surname;
name = textBox1.Text;
surname = textBox2.Text;
this.Hide();
var form3 = new Form3();
form3.Show();
//this is form 5
private void Form5_Load(object sender, EventArgs e)
{
Form1 form1 = new Form1();
label1.Text = form1.name;
label2.Text = form1.surname;
}
表格 5 上标签的默认值为“Placheholder”,由于某些原因,它们不会更改为变量,这是什么问题
在 Form1 上,将字符串设置为
public static string name;
public static string surname;
然后,在Form2
string newSurname;
string newName;
public Form2()
{
InitializeComponent();
newSurname = Form1.surname;
newName = Form1.name;
}