更新:2007 年 11 月
這個範例從 Windows Form 上的文字方塊擷取值,並且在另一表單上的文字方塊中顯示該值。
範例
// In Form1.cs.
private Form2 otherForm = new Form2();
private void GetOtherFormTextBox()
{
textBox1.Text = otherForm.TextBox1.Text;
}
private void button1_Click(object sender, EventArgs e)
GetOtherFormTextBox();
}
編譯程式碼
這個範例需要:
兩個名稱各為 Form1 和 Form2. 的表單。每個表單都包含名為 textBox1 的 TextBox 控制項。Form1 應該建立 Form2 的執行個體,並將它指派給 otherForm;GetOtherFormTextBox 會將 Form2 上 textBox1 中的文字複製到 Form1 上的 textBox1。
在設計階段應該為 Form2 之 textBox1 的 [Text] 屬性指派字串。