你只要把FORM1中的BUTTON1的PRIVATE设为PUBLIC,同时把FORM1和FORM2放在同一个名字空间
解决方案 »
- c# winform如何将dll,sln等一大堆文件做成.exe文件
- 保存xml文件时,如何指定用 utf-8编码呢?
- 怎么修改vs工具的快捷键
- ASP.NET中如何设计界面模板
- 关于datagridview跨列问题
- insert的问题 谢谢
- ToDateTime的问题,急!
- 如何让openFileDialog只能打开一种类型的文件,如只能打开(txt)类型的文件?在线等待!!!
- []内的内容。。。内详!!!!![ClassInterface(ClassInterfaceType.AutoDual)]
- mdi窗口的打开问题
- 各位哪有vs.net下载啊!!!
- 谁能给个实时动态曲线图的源程序?谢谢
Inherits System.Windows.Forms.Form
'创建Form2的一个新的实例
Dim Frm2 As New Form2() Public Function Instance2(ByVal frm As Form2)
Frm2 = frm
End Function Private Sub BtnShowFrm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles BtnShowFrm2.Click
'以下语句保证在Form2以及其他窗体中访问Form1时,
'都将得到Form1的同一个窗体实例。
Frm2.Instance(Me)
Frm2.Show()
Me.Hide()
End SubEnd Class2、Form2中的代码:Public Class Form2
Inherits System.Windows.Forms.Form
Dim frm1 As Form1
'借助一个新增的Instance属性来生成窗体frm1的实例
Public Function Instance(ByVal frm As Form1)
frm1 = frm
End Function Private Sub BtnShowFrm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles BtnShowFrm1.Click
Me.Hide()
frm1.Show()
End Sub Private Sub Form2_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
'如果Form2被关闭,则设置Form1的按钮BtnShowFrm2不可用。
frm1.BtnShowFrm2.Enabled = False
frm1.Show()
End Sub
End Class
Form2 Frm2=new Form2();
Frm2.show();
在Form2 BUTTON事件中加上Form1.show();this.Close();
private void button1_Click(object sender, System.EventArgs e)
{
FrmTwo Form2=new FrmTwo();
Form2.Show();
this.Hide();
}
FrmTwo(form2的类)中button1里面写
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
FrmTwo(form2的类)中Closing时事件里面写
private void FrmTwo_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
form1.cs
==========================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace ZZ
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form1()
{
InitializeComponent();
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} [STAThread]
static void Main()
{
Application.Run(new Form1());
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(288, 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(396, 221);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
this.Hide();
form2.ShowDialog(this);
form2.Dispose();
this.Show();
}
}
}
==================
form2.csusing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace ZZ
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null; public Form2()
{
InitializeComponent();
} 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(204, 100);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 153);
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false); }
#endregion private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
感谢楼上写了出来。form2还要写closing事件。我已经写好了!