作者s880380114 (紧张的taco)
看板Programming
标题Re: [问题] C# 表单间参数的互传
时间Tue May 15 22:10:37 2007
※ 引述《chhuang (Rolling Star)》之铭言:
: ※ 引述《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;
: }
: }
感谢 果然厉害
我也发现把Form2里的变数设为public也能从Form1操作
但是,
我又遇到个问题,
我需要再从Form2里的textbox输入某值让它传回Form1的label,
我试了很久都不行,是因为上面的方法是让fm=new Form2的关系吗?
如果用xxx=new Form1 就出现一个新的form1
【问题就是我想在form2上控制form1的label项】
该如何解决?
★谢谢 感激不尽!★
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.136.112.122
※ 编辑: s880380114 来自: 220.136.112.122 (05/15 22:17)