Form2怎么用Form1中定义的函数啊

解决方案 »

  1.   

    实例化一个Form1对象,对象.方法,方法为public
      

  2.   

    先把Form1 new一下Form1 f = new Form1();Form1 中有一个名为A的公共类f.a();就可以了
      

  3.   

    我在Form1()中已经有socket连上服务器了,在Form2中怎么在用这个socket啊
      

  4.   

    public Form2(Socket xx)
    {}
    Form2 frm=new Form2(Socket);
    frm.show();
    这个是笨办法
      

  5.   

    class Form1 : Form
    {
      // 在 Form1 中声明为静态的:
      public static void S()
      {
        // ...
      }
    }class Form2 : Form
    {
      void Foo()
      {
        Form1.S(); // <------ 在 Form2 中这样用 Form1 中的静态方法
      }
    }
      

  6.   

    在form1中声明的结果体在form2中怎么用啊
      

  7.   

    class Form1 : Form
    {
      public static void S(){}
      public void Func(){}
    }class Form2 : Form
    {
      void Foo()
      {
        Form1.S(); // <------ 在 Form2 中这样用 Form1 中的静态方法
        new Form1().Func(); // <------ 这样用 Form1 中的非静态方法
      }
    }
      

  8.   

    在form1中声明的结果体在form2中怎么用啊
      

  9.   

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
          public    struct xx
            {
                int i ;
                int j ;
                public static  void TT()
                {
                    i = 0;
                    j = 1;
                }
            }
    }
    namespace WindowsFormsApplication16
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
                Form1.xx.TT();
            }
            
        }
    }
      

  10.   

    在form1中声明的结果体在form2中怎么用啊
      

  11.   

    在form2中找不到定义的结构体?
      

  12.   


    class Form1 : Form
    {
      public struct St{}
    }class Form2 : Form
    {
      Form1.St st = new Form1.St(); //  <---- 这样用
    }