public string st;
public From1()
{
       InitializeComponent();}
private void button1_Click(object sender, System.EventArgs e)
{
    st="123";
}
//这是窗体1public From2()
{
       InitializeComponent();}
private void button1_Click(object sender, System.EventArgs e)
{
   From1 f=new From1();
   f.st.Equals("123");
   MessageBox.Show("窗体1的值");
}
//这是窗体2我不知道怎么弄啊 ~ 我试了好次几次都找不f.st.Equals("123");找不到123值
我在From1 直接写 public string st="123"; 它就找的到哦 
高手帮忙急用~~~~~~

解决方案 »

  1.   

    窗体1:
    From2 fr=new From2(st);
    fr.ShowDialog();
    窗体2:
    private string st1;
    public From2(string st)
    {
           st1=st; 
           InitializeComponent();}
    后面就可以用st1了,就把st传到了form2
      

  2.   

    楼上的方法可以,另外,把stl设置成静态全局的就可以了:
    static public string stl;
      

  3.   

    推荐用静态方法
    Form1:
    public static string st;Form2:
    Form1.st.equals("123")
      

  4.   

    当你From1 f=new From1();时,f不再是你原来的那个From1了,它吸是新建一个实例
    当然就没有st的值了
    在Form1:
    public string mstr;
    button1_Click(...)
    {
    mstr="我是父窗口中的字符串";
    }
    button2_Click(..)
    {
    Form2 sw=new Form2();
    sw.main=this;
    sw.Show();
    }
    button3_Click(...)//显示一下该字符串,以确定是否在子窗口button1的按下后改变了?
    {
    if(mstr!=null)
    MessageBox.Show(mstr);
    }
    ------------------------------------------------
    在Form2:
    public Form1 main;
    button1_Click(..)
    {
    if(main.mstr!=null)
    MessageBox.Show(main.mstr);
    main.mstr="我被子窗口改了";
    }