在form2的load事件里用一个公共属性把TextBox.Text的内容得到!

解决方案 »

  1.   

    在form2类中定义一个全局属性:
    public string Result
    {
       get
         {
            return textBox1.Text;
         }
       set
         {
            textBox1.text
    }
      

  2.   

    在form2的load事件里用一个公共属性把TextBox.Text的内容得到!
      
    什么是公共属性!我才学语言!不大清楚!能给我解释一下么?谢谢!
      

  3.   

    在form1中
    public string Result
    {get{return textBox1.Text;}
     set{textBox1.text=value}
    form2中
    form1 f1=new form1();
    this.textBox.text=f1.Result;
    这只是个例子,还有许多要改进的地方!
      

  4.   

    照上面写了一个!public string Result
    {
    get
    {
    return textBox1.Text;
    }
     set
    {
    textBox1.text=value;
    }
    form2
    form1 form1=new form1();
    textBox1.text=form1.Result;
    不行!!没有报错!但,F2里的textBox1.text没有任何显示!
      

  5.   

    全局的域也可以,不过破坏了封装性:
    public string result;
    最好把窗体中的“确定”按钮和“取消”按钮的DialogResult属性设置一下,在确定按钮的Click事件中添加如下代码:
    result=textBox1.Text;
    这样就可以了,很简单。
    如果不想破坏封装性,就把刚才那个全局域定义为私有的,然后在加上一个全局属性:
    private string result;
    public string Result
    {
      get
       {
         return result;
       }
      set
       {
          result=value;
        }
    }
    这样就行了,肯定能用,我自己就是这样用的。