我在form1中的某个方法让form2窗体出现
那么这个时候怎么关闭form1而不关闭form2呢?

解决方案 »

  1.   

    Form2 f=new Form2();
    f.Show();
    this.Close();
      

  2.   

    看到了别人给的建议很受用:方法1:另起一个线程来启动form2;
    方法2:采用简单的办法仅仅将form1隐藏;
    原因是:form1采用的是 application.ran(new form1);启动的一个线程那么如果form1中声明了一个form2的话那么form2也是form1的一部分。form1关闭的话form2也会关闭的!
      

  3.   

    Form2 f2 = new Form2();
    this.Visible = false;
    f2.ShowDialog();
    this.Visible= true;
    试试
      

  4.   

    这个是楼主的第2个方法。
    关闭 form1而不关闭form2,需要把他们隔离起来
      

  5.   

    Form2 f2 = new Form2(); 
    this.Visible = false; 
    f2.ShowDialog(); 
    就将FORM1隐藏.
      

  6.   

    Form2 f=new Form2(); 
    this.Hide();
    f.Show(); 
    this.Close();
    这样就好了
      

  7.   

     static class Program
     {
    /// <summary>
    /// 应用程序的主入口点。
      /// </summary>
       [STAThread] static void Main()
      {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      LeftFrameTest frm = new LeftFrameTest();
      frm.ShowDialog();
      if (LeftFrameTest.bSign)
      Application.Run(new Form1());
      else
       Application.Exit();
      }
     } using System;
     using System.Collections.Generic;
     using System.ComponentModel;
     using System.Data;
     using System.Drawing;
     using System.Text;
     using System.Windows.Forms;
     namespace WindowsApplication1
     {
      public partial class LeftFrameTest : Form
      { 
    public static bool bSign = false;
      public LeftFrameTest() 
    {
    InitializeComponent();
      }
      private void button1_Click(object sender, EventArgs e)
      {
      bSign = true;
      this.Close();
    }
      } 
    }
      

  8.   

    你可以在主窗体中定义 form2的实例,不初始化 ,全局变量。。
    到form1中初始化啊这样关闭form1,就不关form2的事情哦。。或者像上面说的重新开一个进程或者只隐藏form1
      

  9.   

    最简单的方法就是把form1隐藏起来
      

  10.   


    (1)主程序中生成form1;
    (2)在form1中,生成from2;
        Form2 f=new Form2();
        f.Show();
    (3)关闭form1,主程序保留
         this.Close();
      

  11.   

    隐藏form1就行了吧?一定要关闭吗?
    那不能在form1中实例化form2,这样产生父子关系了吧?
    试试多线程
      

  12.   

    code:
      
    this.Visible = false;
    form2.Show();
      

  13.   

    Form2 form2=new Form2;
    form2.show();//show方法显示创建的Form2窗体
    this.close();//this代表当前窗体,关闭当前的Form1窗体
      

  14.   


    在Program类中static class Program   
    {   
    internal static ApplicationContext context = new ApplicationContext(new Form1());   
    /// <summary>   
    /// 应用程序的主入口点。   
    /// </summary>   
    [STAThread]   
    static void Main()   
    {   
    Application.EnableVisualStyles();   
    //Application.SetCompatibleTextRenderingDefault(false); 这句要注释掉,否则会出错   
    Application.Run(context);   
    }   
    }  
    然后这样显示窗体:
    view plaincopy to clipboardprint?
    Form2 form = new Form2();   
    Program.context.MainForm = form;   
    form.Show();  
      

  15.   

     Form2 f=new Form2();
     f.Show();
     this.Hide();
      

  16.   


    form1 是登录窗口,登录成功后关闭form1,进入from2?可以把form2注册为启动窗口,然后再form2.load里启动一个form1为模态窗口
    这样一启动就先模态弹出form1,登录成功就form1.close(),失败就Application.exit().
      

  17.   

    Form2 f=new Form2();
    f.Show();
    this.Close();
      

  18.   

    一种方法:
    Form2 frm2 = new Form2()在Form1内:
      
    private Form2 frm2;public Form1(Form2 frm):this(){
      this.frm2 = frm;
    }// 关闭函数 
    private void CloseForm(){
    if(this.frm2!=null){
      frm2.Show();
      this.close();
    }
    另一种:
    你可以在创建Form3,在这个主窗口控制Form2和Form1的关闭和显示
    }
      

  19.   

    frm1 会关闭是因为你的Main() 函数写在Form1的类中。把程序入口从From1中调出来就行了。然后参照1楼的方法
      

  20.   

    关闭了主线程就结束了,程序关闭了,form2就没了