在Form2类中定义一个变量来保存Form1的一个实例。public Form1 myForm1 = null;然后把Form1打开的Form2的代码修改如下:
 this.Hide();
            partsForm = new Form2();
            partsForm.myForm1 = this;
partsForm.Show();
partsForm.Activate();在Form2的close事件中,
调用
if ( this.myForm1 != null)
this.myForm1.Show();

解决方案 »

  1.   

    这样做肯定是可以的。
    能不能从系统角度来解决这个问题,也就是使用APPLICATION 类,或THIS 指针 。
      

  2.   

    APPLICATION 并不维护每一个你打开窗体的实例。this是本类的一个实例。跟这个问题没有关系吧?如果不怕麻烦,你可以用FindWindows把这个窗体找出来,然后发送消息让他显示。
      

  3.   

    你说的方法我已经测试过了。
    在FORM1 中 并不能使用
    partsForm.myForm1 = this; 这条语句,也就是说在FORM2 定义的变量,并不能在FORM1带码中被调用。只有在FORM2 的代码中,才可以调用。
      

  4.   

    还是看下面的代码吧,Form1.cs,Form2.cs,拷贝到你的程序中,看看会不会出错。注意是两个文件。using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication2
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(184, 72);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion public static void Main()
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    this.Hide();
    Form2 partsForm = new Form2();
    partsForm.myForm1 = this;
    partsForm.Show();
    partsForm.Activate(); }
    }
    }//Form2.cs
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication2
    {
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1 myForm1 = null; public Form2()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // Form2
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Name = "Form2";
    this.Text = "Form2";
    this.Closed += new System.EventHandler(this.Form2_Closed); }
    #endregion private void Form2_Closed(object sender, System.EventArgs e)
    {
    if (this.myForm1 != null)
    this.myForm1.Show();
    }
    }
    }