Form1中代码
        static string value1;
        private static string getvalue;
        private void button1_Click(object sender, EventArgs e)
        {            value1= textBox1.Text;
            Form2 f2 = new Form2();
            f2.Show();
        }
        public static string GetV
        {
            set { getvalue = value1; }
            get { return getvalue; }
        }
Form2中的代码
        private void Form2_Load(object sender, EventArgs e)
        {
            textBox1.Text = Form1.GetV;
        }
我想实现的是把通过单击form1中的button把form1中的textbox内容传给Form2中的text,运行后Form2的textbox中为空,能帮忙在我的程序上修改嘛?我也说不清楚我那里错了。谢谢
注:2个窗口不存在父子关系。

解决方案 »

  1.   

    Form1中代码,处理按钮事件private void button1_Click(object sender, System.EventArgs e)
    {
    Form2 f2 = new Form2();
    f2.Value = this.textBox1.Text.Trim();
    f2.Show();
    }Form2中代码private string strValue;
    public string Value
    {
    get { return strValue; }
    set { strValue = value; }
    }//窗体的Load事件
    private void Form2_Load(object sender, System.EventArgs e)
    {
    this.textBox1.Text = Value;
    }
      

  2.   

    小写的value是一个什么值,怎么是蓝色的程序固有的?
      

  3.   

    对,那个系统的。
    是属性set设置的固定格式
      

  4.   

    Lz你好 不妨这样    
     Form2中的代码
            static string value1; 
            private static string getvalue; 
            private void button1_Click(object sender, EventArgs e) 
            { 
                GetV = textBox1.Text.trim(); 
                Form2 f2 = new Form2(); 
                f2.Show();
            } 
            public static string GetV 
            { 
                set { getvalue = value1; } 
                get { return getvalue;}
            }     Form2中的代码 
            private void Form2_Load(object sender, EventArgs e) 
            { 
                textBox1.Text = Form1.GetV; 
            } 
    在Form2中你取的是GetV 这个属性的值,所以在Form1中应当给属性GetV 赋值
      

  5.   

    你的属性写的有问题
    建议先将光标放到字段上,再用快捷键Ctrl+R,Ctrl+E 再回车
    或 直接右键重构 字段即可自动生成属性在取值前先判断下是否为null较安全哦
      

  6.   

    楼上的可行,但是“再用快捷键Ctrl+R,Ctrl+E 再回车 ”为什么要密封字段呢?
      

  7.   


    不可能的,我试过的。
    Form2中的
    private string strValue;
    public string Value
    {
        get    {    return strValue;    }
        set    {    strValue = value;    }
    }
    要写成全局变量
      

  8.   

    5樓用了靜態成員(static),可以。如果是這樣,
    可以form2的textbox1設成public的        public System.Windows.Forms.TextBox textBox1;//在Form2.Designer.cs中。在form1中寫上        private void button1_Click(object sender, EventArgs e)
            {
                Form2 form2 = new Form2();
                form2.textBox1.Text = textBox1.Text;
                form2.Show();
            }
      

  9.   


    LZ方法本身的问题是你根本就没有给 getvalue 赋过值啊.你赋值的是value1。

    value1= textBox1.Text;后加上GetV=value1
      

  10.   

    用public属性啊,又不是在web上用的,还要用get和set。