比如Form1中TextBox1中输入姓名,Form2中的Lable显示输入的姓名,怎么传递?请大家写详细一点,我是个菜鸟。写的详细的我肯定加分多。O(∩_∩)O谢谢

解决方案 »

  1.   

    Lable的modifers设置为public就可以直接form2.Lable了,当然不推荐,你还是好好看看面向对象,用属性传递
      

  2.   

    要获取值得话,就要先在  FORM2 中申请 form1 的对象 通过对象访问值 。
      

  3.   

    Form2:写个属性   public string LabelTxt
            {
                set
                {
                    this.label1.Text = value;
                }
            }然后 Form1:
       private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm = new Form2();
                frm.LabelTxt = this.textBox1.Text;
                frm.Show();        }
      

  4.   

    form1 f1=new form1()
    初始化
    这样后那个textbox1里的值就为空了
      

  5.   

    (一般传值,使用委托会很强大 ,很方便)
    说个简单的,在项目里添加一个类,其中放一个public静态变量,如CurName姓名,
    这样,Form1中给姓名赋了值,Form2就可以访问到了
      

  6.   

    Form2写个方法,满足你的想法        public void ShowValue(Form1 frm)
            {
                this.label1.Text = frm.txt;
            }Form1:这样写 public string txt
            {
                get
                {
                    return this.textBox1.Text;
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {            Form2 frm = new Form2();
                frm.ShowValue(this);
                frm.Show();
            }
      

  7.   

       //单击Form2中的按钮,显示Form1。然后在form1 textbox中输入字符串,Form2中的textbox相应显示。 这个可以满足你的要求。大致一直如下
    public delegate void Callback(string str);
      public Class Form1()
            {
       public event Callback Callevent=null;
              private void button1_Click(object sender, EventArgs e)
            {
           Callevent(textBox1.Text);
              } 
        } 
        
      public Class Form2()
    {               private void button1_Click(object sender, EventArgs e)
            {
     
              Form1 child = new  Form1();
                chil.Callevent += (send) =>
                  {
                      textBox1.Text = send;
                  }; child.Show();
    }
    }
      

  8.   

    form1:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication5
    {
      public partial class Form1 : Form
      {
      public Form1()
      {
      InitializeComponent();
      //textBox1.Leave += new EventHandler(textBox1_Leave);  
          }  private void Form1_Load(object sender, EventArgs e)
      {  }  private void button1_Click(object sender, EventArgs e)
      {
      string a = textBox1.Text;
      Form2 frm2 = new Form2(a);
      frm2.Show();  }  }
    }
    form2:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication5
    {
      public partial class Form2 : Form
      {
      public Form2()
      {
      InitializeComponent();
      }  public Form2(string a)//重写构造方法
      {
      InitializeComponent();
      label1.Text = a;
      }
      }
        
    }O(∩_∩)O
      

  9.   

    Label要得到值,要么去Form1那里取,那么就要让TextBox公开,让Form1能够访问到...
    要么就是让Label可以访问得到,让Form1能够操作它...属性  就是干这事滴