Re: [問題] C# 表單間參數的互傳

看板Programming作者 (Rolling Star)時間18年前 (2007/05/11 21:13), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/6 (看更多)
※ 引述《s880380114 (緊張的taco)》之銘言: : 我在Form1新增了一個Form2 : 我想要在Form1的TextBox裡面輸入數值 : 然後傳到Form2的LabelL讓它顯示出來 : 該怎麼做 : 我的程式碼 : 按鈕跳出FORM2 : Form2 fm= new Form2(); : fm.Show; : fm.label1.Text = Form1.TextBox1.Text; : (我想讓它顯示在form2的LABEL) : 這樣不行 : 請問這樣大致上是哪裡有錯? 在 Form2 裡封裝 label1.Text 的值欄位...記得設定為 public 存取... public partial class Form2 : Form { private string _labelText; public string LabelText { get { return label1.Text; } set { label1.Text = value; } } } 然後再 Form1 裡面...對 fm.LabelText 操作...就表示操作 Form2 的 label1.Text public partial class Form1 : Form { Form2 fm = new Form2(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { fm.Show(); fm.LabelText = this.textBox1.Text; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.62.84.89
文章代碼(AID): #16H6lU9M (Programming)
文章代碼(AID): #16H6lU9M (Programming)