c#

在c#中怎么在窗体与窗体之间传递值

解决方案 »

  1.   

    其他方法
    http://blog.csdn.net/c_sharp_Rookie/archive/2009/12/08/4964258.aspx
      

  2.   

    这个问题已经被提过无数次了:
    http://topic.csdn.net/u/20110407/19/c1068d69-7331-4d02-bc0b-f5ba7a5f8dd8.html
      

  3.   

    可以建一个类:
    public Class{
      private static string numOne;
      ....
    }
    然后  类名.字段名就可以访问了
      

  4.   


    主窗体:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace StudyWinform
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f = new Form2(textBox1.Text);
                f.Owner = this;
                f.Show();
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        public void SetData(string a)
            {
                textBox1.Text = a;
            }
        }
    }
    子窗体:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace StudyWinform
    {
        public partial class Form2 : Form
        {
            public Form2(string data)
            {
                InitializeComponent();
                this.Data = data;
            }        public string Data { get; set; }        private void button1_Click(object sender, EventArgs e)
            {
                Form1 f = this.Owner as Form1;
                f.SetData(textBox1.Text);
                this.Close();
            }        private void Form2_Load(object sender, EventArgs e)
            {
                textBox1.Text = Data;
            }        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
            {
                Form1 f = this.Owner as Form1;
                f.SetData(textBox1.Text);
            }
        }
    }
      

  5.   

    方法有很多,找个自己适用的。BAIDU GOOGLE