将form1 ,form2 设为public
window a
Form2 a = new Form2();
a.Show();window b
//hide
form1 b=new form1();
b.hide();
//show
b.show

解决方案 »

  1.   

    static void Main(){
      Form1 formA = new Form1();
      Form2 formB = new Form2();
      formA.Hide();
      Application.Run(formB);
      //这样 form B 是启动窗体了
    }
    在 formB 里面  为 formA 的 Hide,Show 方法控制 formA 了
      

  2.   

    form1,form2form2中声明:form1 myfm1;
    form2(form1 fm1){ //构造函数
     myfm1 = fm1;
    }
    myfm1.Hide();  //隐藏
    myfm1.Show();  //显示form1中:
    form2 fm2 = new form2(this);
    fm2.Show();
      

  3.   

    我的意思是,FormA为启动窗体,B为通过A中的按钮出现,B出现后再控制A。望大家再次回复,谢谢!
      

  4.   

    Form1.csusing System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace FormToForm
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button Form1Button;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Form1Button = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // Form1Button
    // 
    this.Form1Button.Location = new System.Drawing.Point(184, 232);
    this.Form1Button.Name = "Form1Button";
    this.Form1Button.Size = new System.Drawing.Size(88, 23);
    this.Form1Button.TabIndex = 0;
    this.Form1Button.Text = "Form1Button";
    this.Form1Button.Click += new System.EventHandler(this.Form1Button_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.Form1Button});
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1Button_Click(object sender, System.EventArgs e)
    {
    Form2 NewForm = new Form2( this);
    NewForm.Show();
    }
    }
    }
    Form2.cs
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace FormToForm
    {
    /// <summary>
    /// Summary description for Form2.
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button Form2Button;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    private System.Windows.Forms.Button ShowForm1;
    Form1 PreForm; public Form2( Form1 form1)
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    // PreForm = form1; } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.Form2Button = new System.Windows.Forms.Button();
    this.ShowForm1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // Form2Button
    // 
    this.Form2Button.Location = new System.Drawing.Point(176, 192);
    this.Form2Button.Name = "Form2Button";
    this.Form2Button.Size = new System.Drawing.Size(80, 23);
    this.Form2Button.TabIndex = 0;
    this.Form2Button.Text = "Form2Button";
    this.Form2Button.Click += new System.EventHandler(this.Form2Button_Click);
    // 
    // ShowForm1
    // 
    this.ShowForm1.Location = new System.Drawing.Point(176, 240);
    this.ShowForm1.Name = "ShowForm1";
    this.ShowForm1.TabIndex = 1;
    this.ShowForm1.Text = "ShowForm1";
    this.ShowForm1.Click += new System.EventHandler(this.ShowForm1_Click);
    // 
    // Form2
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.ShowForm1,
      this.Form2Button});
    this.Name = "Form2";
    this.Text = "Form2";
    this.Closing += new System.ComponentModel.CancelEventHandler(this.Form2_Closing);
    this.ResumeLayout(false); }
    #endregion private void Form2Button_Click(object sender, System.EventArgs e)
    {
    PreForm.Hide();
    } private void ShowForm1_Click(object sender, System.EventArgs e)
    {
    PreForm.Show();
    } private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    Application.Exit();
    }
    }
    }
    Form1 设为启动 窗体, 按钮 弹出 Form2,此时 Form 一个按钮控制 隐藏  Form1,一个显示 Form1 
    上例中 Form1 为父窗体,Form2为子窗体