让form2获取hxy的唯一实例
class hxy
{
   private static hxy hxyInstance;
   public static hxy GetInstance()
   {
      if(hxyInstance == null)
         hxyInstance = new hxy();
      return hxyInstance;
   }
   public hxy()
   {
      ...
      hxyInstance = this;
   }
}

解决方案 »

  1.   

    楼上的大哥,我试过了~~不行啊~~~
    可能是我说得不清楚吧~~~
    ////////////////////////////// 独立的hxy类////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    public class hxy
    {
    public string temp;     //为了测试是否可以共享使用
    private static hxy hxyInstance;
    public static hxy GetInstance()
    {
    if(hxyInstance == null)
    hxyInstance = new hxy();
    return hxyInstance;
    }
    public hxy()
    {
    hxyInstance = this;
    } }
    //////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////// 窗体Form1 /////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    private void Form1_Load(object sender, System.EventArgs e)
    {
    hxy h=new hxy();       //实例化 hxy class
    h.temp="hello world!"; //为了看效果 给temp赋值
    Form2 f2=new Form2();
    f2.Show();
    }
    //////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////// 窗体Form2 /////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////
    private void Form2_Load(object sender, System.EventArgs e)
    {
    //这里如何才写 才能调用已经在Form1窗体实例化的hxy类?
    }
    //////////////////////////////////////////////////////////////////////////////
    顺便问一下~~~如何 结此问题~~~嘿嘿~~~新手~~~高手别笑话我 谢谢啦
      

  2.   

    自定义类或者使用Web Services
      

  3.   

    vb6.0 中在第一个模块声明的 公有的变量 可以在所有 窗体中操作c# 不知道用什么好方法可以实现。5555~~~~高手在帮我想想办法~~~~我想如果所有的数据库操作 都封装在一个class中 所有的窗体都可以共享一个已经实例化的class 就好了~~~不知道除了 以上我说的那个方法~~还有什么可以 实现这一个目的的?再次 谢谢高手!哪怕只是浏览不回的朋友~~~~   :)
      

  4.   

    单例模式 + 上面说的public class hxy
    {
    private static hxy hxyInstance = new hxy();
    public static hxy HxyInstance
    {
    return hxyInstance;
    }
    }
      

  5.   

    hxy.HxyInstance.temp show() 一下试试
      

  6.   

    public class hxy
    {
    public string temp;
    private static hxy hxyInstance = new hxy(); public static hxy HxyInstance()
    {
    return hxyInstance;
        }
    public static hxy GetInstance()
    {
    if(hxyInstance == null)
    hxyInstance = new hxy();
    return hxyInstance;
    }
    public hxy()
    {
    hxyInstance = this;
    temp="失败~~~";
    } }这样写对吗????俺蔡~~~都晕晕了~~~~~~