如何实现多个窗口之间的切换 在.net中可不可以在一个工程中建立多个窗口,然后通过点击其中一个窗口中的按钮,切换到另外的一个窗口中?请大家指教,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 this.Hide();(new Form2()).Show(); using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;namespace Test{ class RunMain:Form { Form1 fr1; Form2 fr2; static void Main() { Application.Run(new RunMain()); } RunMain() { fr1 = new Form1(); fr2 = new Form2(); fr1.ChangeForm += new EventHandler(fr1_ChangeForm); fr2.ChangeForm += new EventHandler(fr2_ChangeForm); fr1.Show(); this.Visible = false; } void fr2_ChangeForm(object sender, EventArgs e) { fr2.Visible = false; fr1.Show(); } void fr1_ChangeForm(object sender, EventArgs e) { fr1.Visible = false; fr2.Show(); } } public partial class Form1 : Form { public event EventHandler ChangeForm; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (ChangeForm != null) this.ChangeForm(sender, e); } } partial class Form1 { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(28, 42); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(295, 155); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; } public partial class Form2 : Form { public event EventHandler ChangeForm; public Form2() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { if (this.ChangeForm != null) { this.ChangeForm(sender, e); } } } partial class Form2 { private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button2 // this.button2.Location = new System.Drawing.Point(35, 28); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 0; this.button2.Text = "button2"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form2 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(311, 180); this.Controls.Add(this.button2); this.Name = "Form2"; this.Text = "Form2"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button2; }} C#如何启动代理发送邮件 谁有序列化和反序列化的公共方法。 求助,如何设置表单提交后点击后退出现“警告: 网页已经过期 ” 如何实现程序入口窗体关闭 程序不退出? 请问怎样实现DevExpress用代码实现横打?大家帮帮忙.. 请教布儿运算问题 (散分~~~)世界没有程序员,会是什么样 vs2005中怎样打包数据库? 请教msdn的问题,急!!! 不太理解C#中索引器的用法,可否给个通俗易懂的解释? Infragistics的树问题 :如果获取选中的子节点以及所属的父节点的TEXT和ID? 关闭所有活动窗体
(new Form2()).Show();
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;namespace Test
{
class RunMain:Form
{
Form1 fr1;
Form2 fr2;
static void Main()
{
Application.Run(new RunMain());
} RunMain()
{
fr1 = new Form1();
fr2 = new Form2();
fr1.ChangeForm += new EventHandler(fr1_ChangeForm);
fr2.ChangeForm += new EventHandler(fr2_ChangeForm);
fr1.Show();
this.Visible = false;
}
void fr2_ChangeForm(object sender, EventArgs e)
{
fr2.Visible = false;
fr1.Show(); } void fr1_ChangeForm(object sender, EventArgs e)
{
fr1.Visible = false;
fr2.Show();
}
}
public partial class Form1 : Form
{
public event EventHandler ChangeForm;
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
if (ChangeForm != null)
this.ChangeForm(sender, e);
}
}
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(28, 42);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(295, 155);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1;
}
public partial class Form2 : Form
{
public event EventHandler ChangeForm;
public Form2()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
if (this.ChangeForm != null)
{
this.ChangeForm(sender, e);
}
}
}
partial class Form2
{
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button2
//
this.button2.Location = new System.Drawing.Point(35, 28);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 0;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(311, 180);
this.Controls.Add(this.button2);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button2;
}
}