将form1 ,form2 设为public
window a
Form2 a = new Form2();
a.Show();window b
//hide
form1 b=new form1();
b.hide();
//show
b.show
window a
Form2 a = new Form2();
a.Show();window b
//hide
form1 b=new form1();
b.hide();
//show
b.show
解决方案 »
- C#簡單的問題。。
- 查询语句问题 谢谢大家 出来马上结贴 在线等
- 问一个关于WebBrowser控件post数据的问题
- 老是提示将参数值从string转换到datetime失败 是怎么回事
- [100分]求免费日程控件[winform]
- 在C#中建立空项目我的问题
- 为什么我不能新建web应用程序/服务?
- c#.net应用中,怎么在点击一个按钮后,弹出一个对话框,对话框上面显示警告图标,和是,否,取消????????
- C# PrintDocument调用针式打印机没有反应,调用普通打印机可以打出来, 求高手指点!!!
- 再C#中怎样实现类似windows资源管理器的功能
- 如何动态创建一个标准控件在groupbox里?
- 为何功能键不能触发keypress事件,请教!
Form1 formA = new Form1();
Form2 formB = new Form2();
formA.Hide();
Application.Run(formB);
//这样 form B 是启动窗体了
}
在 formB 里面 为 formA 的 Hide,Show 方法控制 formA 了
form2(form1 fm1){ //构造函数
myfm1 = fm1;
}
myfm1.Hide(); //隐藏
myfm1.Show(); //显示form1中:
form2 fm2 = new form2(this);
fm2.Show();
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为子窗体