先在Form2中定义一个Form1类型的变量来保存Form1的一个实例。在Form2.cs中,
public Form1 myParentForm = null;打开的时候,
Form2 f1=new Form2();
f1.Owner=this;
                           f1.myParentForm = this;
f1.ShowDialog();以后就可以用myParentForm来调用了。

解决方案 »

  1.   

    我在Form2.cs中是这样调用的
    ((Form1)this.Owner)
    不过偶又有问题了
    我在Form1中有一个SqlConnection 的public变量conn,已经赋值,但是还没有Open()
    我在Form2中有一个SqlConnection 变量conn1,我把conn1=((Form1)this.Owner).conn;
    但是
    str="select top 1 * from manager where name='"+strName+"' and password='"+strPassword+"'and isdead=0";
    SqlCommand cm=new SqlCommand(str,conn1);
    SqlDataReader dr = cm.ExecuteReader(); ///这步出错,提示是系统错误,System.SqlException