我已将输入保存到列表中,如何将其显示在下一个表单的文本框中? 到目前为止,这是我的代码。
Form1(文本框所在的位置)
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
Class1 a = new Class1();
a.minLista.Add(textBox1.Text);
Form2 Form1 = new Form2();
this.Hide();
Form1.Show();
}
}
}
列表所在的类
namespace WindowsFormsApplication4
{
public class Class1
{
public List<string> minLista = new List<string>();
}
}
答案 0 :(得分:1)
将列表定义为
namespace WindowsFormsApplication4
{
public class Class1
{
public static List<string> minLista = new List<string>();
}
}
并在 form1 loading 中写为
txtVal.Text= Class1.minLista[0];