比如我有一个form1,里面有一个确定按钮.还有一个form2,form2里面有一个textBox
就是当我点击确定按钮的时候我要弹出一个消息框显示form2里面textBox的值要怎么办?
现在我不想用构造方法传值,请各位大侠多多指教

解决方案 »

  1.   

    设计一个event,form1触发之,form2响应之
      

  2.   

    使用public 定义一个变量存放该值
    或者
    form2.textbox1.text获得
      

  3.   


    需要手动修改 Form1的
    private void InitializeComponent()

    public void InitializeComponent()
    在使用下面的方法
    Form1 f = new Form1();
    string dd=f.textBox1.Text;
      

  4.   

    把自己静态化,在窗口中定义个静态变量(类型就是自己),在自己的Load中把this赋给这个静态变量,
    Closing时再赋null,其他窗口调用它直接使用这个静态变量,但缺点是此窗口类不能同时打开多个
      

  5.   

     我的意思是在form1窗体的按钮点击事件中去获取form2的textBox的值
    就是说我在点击事件中去把form2 new出来,可是却点不出form2的textBox
    不知如何是好
      

  6.   

    需要手动修改 Form2的 
    private void InitializeComponent() 
    为 
    public void InitializeComponent() 
    在使用下面的方法 
    Form2 f = new Form2(); 
    string dd=f.textBox1.Text;
      

  7.   

    把Form2的textbox的text设计成Form2的属性来访问即可。
    Form1 using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private Form2 frm = new Form2();        private void button1_Click(object sender, EventArgs e)
            {            MessageBox.Show(frm.TextBoxText);
            }        private void Form1_Load(object sender, EventArgs e)
            {
                frm.Show();
            }
        }
    }
    Form2
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
                this.textBox1.Text = "aaa";//为了看到效果,随便给的值
            }        // private string text;        public string TextBoxText
            {
                get { return this.textBox1.Text; }
                set { this.textBox1.Text = value; }
            }    }
    }
      

  8.   

    或者在Form2.Designer.cs里面
    把private System.Windows.Forms.TextBox textBox1;
    修改成public System.Windows.Forms.TextBox textBox1;
    然后在.....
    Form2 f = new Form2(); 
    string dd=f.textBox1.Text;
      

  9.   

    Windows窗体间的数据交互的问题,楼主请看这里,
    http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
    http://blog.csdn.net/zhzuo/archive/2006/05/05/708941.aspx