步驟
可以通過構造函數在兩個窗體間傳遞參數。例子由Form1傳遞到Form2(Form1和Form2對應控件略)。
Form1代碼:
1 //…… 2 public partial class Form1 : Form 3 { 4 public Form1() 5 { 6 InitializeComponent(); 7 } 8 9 private void button1_Click(object sender, EventArgs e) 10 { 11 Hide(); 12 Form2 form = new Form2(textBox1.Text); 13 form.ShowDialog(); 14 Show(); 15 } 16 } 17 //……
Form2代碼:
1 //…… 2 string text ; //用於獲取傳遞的參數 3 public Form2() 4 { 5 InitializeComponent(); 6 } 7 8 public Form2(string text) 9 { 10 InitializeComponent(); 11 this.text = text; 12 } 13 14 private void Form2_Load(object sender, EventArgs e) 15 { 16 label1.Text = "Hello, world!" + text; 17 } 18 //……
參考網址
[1] https://wenku.baidu.com/view/0ab6226687c24028915fc395.html