作者chhuang (Rolling Star)
看板Programming
标题Re: [问题] C# 表单间参数的互传
时间Fri May 11 21:13:01 2007
※ 引述《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