两个窗体form1,form2.打开form1之后,点button1 关闭它 ,然后显示form2;我的代码是:
this.hide();
form2 f2=new form2();
f2.show();
//问题是this.hide();是把form1隐藏了,仍然驻留在内存中.
那么请问:怎样才能把form1彻底释放掉,再打开form2呢??

解决方案 »

  1.   

    这样写便行:
    this.hide(); 
    form2 f2=new form2(); 
    f2.ShowDialog(); 
    this.Close();
      

  2.   

    在主函數里面設置一個BOOL型的全局變量HAHA=FALSE;
      然后點擊BOOTON1的時候
      先把變量改為TRUE
    然后FROM1.CLOSE(); 就可以了主函數的為
     Application.Run(new Form1());
    if(HAHA=TRUE)
    { Application.Run(new Form2());}
       
      

  3.   

    你可以先打开form2,再关闭form1
    button1_Click()
    {
       form2 frm2 = new form2();
       frm2.show();
       this.close();
    }
      

  4.   

    主窗体,也就是入口不能关的,除非你的窗体二是独立在项目外的;
    推荐你用先前的思路,把窗体一hide掉
    在窗体二的关闭事件里面加
    Application.Exit();//结束应用程序
    这样就可以把关联的窗体都干了.
      

  5.   


    button1_Click()
    {
       this.hide(); 
       form2 frm2 = new form2();
       frm2.show();
    }
      

  6.   

    [DllImport("user32.dll",CharSet=CharSet.Auto)]
    public static extern int SendMessage(int hWind,int msg,int wParam,int lparam)static IntPtr hand=IntPtr.Zero;定义完后,在方法里if(hand!=IntPtr.Zero)
       SendMessage(hand.ToInt32(),0x00010,0,0)
    hand=s.Handle;获取窗口的句柄,然后关闭前一个窗体
      

  7.   

    传this在form2的构造函数,关闭即可
    public Form2(Form1 f1)
    {
    f1.close();
    }
    button1_Click() 
    {
       form2 frm2 = new form2(this); 
       frm2.show(); 
    }
      

  8.   

    public Form2(Form1 f1) 

    f1.close(); 

    button1_Click()  

       form2 frm2 = new form2(this);  
       frm2.show();  
    }