求代码,谢谢

解决方案 »

  1.   

    要求,
    单击form1中按钮,出现form2窗口,
    单击form2中按钮,将form2中textbox中文字传到from1中。
      

  2.   

    通过参数传递。
                   Form1 f = new Form2(Para);
                 两个Format 必须都存在;
          传递给Form1是什么情况,你没有说明,也就无法回答!
      

  3.   

    方式很多,可以在 form2 里引发一个事件, form1 里订阅这个事件也可以在 form2 里直接调用 form1 的方法,或者干脆把 form1 的 textbox 传给 form2怎么省事怎么来
      

  4.   

    传递给form1的lable
    给代码吧
      

  5.   

    using System;
    using System.Windows.Forms; class Form1 : Form 

      Form1()
      {
        Label lbl   = new Label();
        lbl.Parent  = this;
        
        Button btn  = new Button();
        btn.Parent  = this;
        btn.Text    = "新窗口(&N)";
        btn.Top     = 30;
        btn.Click  += delegate { new Form2(lbl).ShowDialog(); };
      }
      
      static void Main() 
      {
        Application.Run(new Form1()); 
      } 
    }class Form2 : Form
    {
      public Form2(Label lbl)
      {
        TextBox tbx = new TextBox();
        tbx.Parent  = this;
        
        Button btn  = new Button();
        btn.Parent  = this;
        btn.Text    = "应用(&A)";
        btn.Top     = 30;
        btn.Click  += delegate { lbl.Text = tbx.Text; };
      }
    }
      

  6.   

    Form2(lbl)
    有没有其它方法啊,
    我想这样:
    单击form1中的菜单,
    出现form2,
    在form2中输入文字,
    单击按钮,
    关闭form2,
    form1中获得form2中输入的文字
      

  7.   


    using System;
    using System.Windows.Forms; class Form1 : Form 

      Form1()
      {
        Label lbl   = new Label();
        lbl.Parent  = this;
        
        Button btn  = new Button();
        btn.Parent  = this;
        btn.Text    = "新窗口(&N)";
        btn.Top     = 30;
        btn.Click  += delegate
        {
          Form2 form2 = new Form2();
          form2.ShowDialog();
          lbl.Text = form2.tbx.Text; 
        };
      }
      
      static void Main() 
      {
        Application.Run(new Form1()); 
      } 
    }class Form2 : Form
    {
      public TextBox tbx;
      
      public Form2()
      {
        tbx         = new TextBox();
        tbx.Parent  = this;
        
        Button btn  = new Button();
        btn.Parent  = this;
        btn.Text    = "确定(&A)";
        btn.Top     = 30;
        btn.DialogResult = DialogResult.OK;
      }
    }
      

  8.   


    还可以把 form2 弄成模式对话框,看情况定,你怎么会想要码呢,我一直想要无码的
      

  9.   

    form1
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.ShowDialog();
                label1.Text = AppDomain.CurrentDomain.GetData("txt").ToString();
            }form2
            private void button1_Click(object sender, EventArgs e)
            {
                AppDomain.CurrentDomain.SetData("txt", textBox1.Text);
            }
      

  10.   

    窗体间传值方式很多
     public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        public string TextBox1Text
            {
                set { this.textBox1.Text = value; }
                get { return this.textBox1.Text;  }
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 frm2 = new Form2();
                frm2.Show(this);
            }
        }    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        private void button2_Click(object sender, EventArgs e)
            {
                Form1 frm1 = (Form1)this.Owner;
                frm1.TextBox1Text = this.textBox2.Text;
                this.Close();
            }
        }
      

  11.   

    通过 ShowDialog()进行传值;
    通过改造构造函数进行传值
    通过公共静态类进行传值;
    通过绑定事件进行传值;
    使用Attribute
    参考