t2=t1;//变量t2的值是t1的引用
t2.Text="dddddddd";//实际是改变了t1的text
MessageBox.Show(t1.Name+"  "+t1.Text);
MessageBox.Show(t2.Name+"  "+t2.Text);
//输出的都是t1的属性
for(int i=0;i<this.Controls.Count;i++)
{
MessageBox.Show(this.Controls[i].Name+":text="+this.Controls[i].Text);//输出form里所有的control(button1,t1,t2)其中t1在上面已经改变,t2内容没有改变
}
}

解决方案 »

  1.   

    because aftert2=t1;both t2 and t1 reference the same textbox, in this case, t1but the TextBox controls will not change their name/Text, unless you specifically change them, tryt2.Name=t1.Name;
    t2.Text = t1.Text;
    t2. = t1;
    t2.Text="dddddddd";
    ....
      

  2.   

    那么怎么样实现把textbox2的属性全部跟textbox1一样呢,我现在想实现这个效果?请问高手怎么实现?
      

  3.   

    either you have to do
    t2.Name=t1.Name;
    t2.Text = t1.Text;
    ....or you have to use Reflection (you might need to use the overloaded GetProperties() to get the private properties) (didn't test, so it might not work):using System.Reflection;foreach (PropertyInfo pi in t2.GetType().GetProperties())
    {
       pi.SetValue(t2, pi.GetValue(t1,null),null);
    }
      

  4.   

    这样是不是很累赘,象其他的语言比如Delphi中随便就能搞定的问题怎么在这里变的这么麻烦?
      

  5.   

    因为我现在要在不同Form间保持同步,上面的方法不能达到效果? saucer(思归),你能否想一个比较便捷的办法!
      

  6.   

    我还有些不明白,例如:
    private System.Windows.Forms.TextBox t1;
    private System.Windows.Forms.TextBox t2;
    private void button1_Click(object sender, System.EventArgs e)
    {
         t1 = t2;
         ...
    }
     也就是说,这里的t1和t2都是引用,而不是对象了??