偶想这就是原因:
“
在Form2里面这样打开Form1
Form1 form1=new Form1();
form1.Show();
”
这是一个变量作用域的问题。
这里的Form1你是在Form2里面声明的,等于新生成了一个窗体,这样就与先前声明的Form1并无关系。由于不知道你的源码如何,你可以去看看名称空间和变量作用域这方面的问题。
“
在Form2里面这样打开Form1
Form1 form1=new Form1();
form1.Show();
”
这是一个变量作用域的问题。
这里的Form1你是在Form2里面声明的,等于新生成了一个窗体,这样就与先前声明的Form1并无关系。由于不知道你的源码如何,你可以去看看名称空间和变量作用域这方面的问题。
解决方案 »
- c# 获取本地扫描仪驱动
- 请问如何触发控件的其他的事件呢?
- 我要写一个批量更名的小工具,不知道有没有人做过.介绍一下经验!
- 有没有懂得c++和c#的好心高手可以帮我把一个c++的程序改成c#的程序啊?
- 关于加密算法的问题.在线等!!!
- MVP Summit 2004: Indigo, WSE2.0,XP SP2,WhiteHorse技术预览
- 字符串转换
- C# 256色位图显示问题~
- C# 选中datagridviewcomboboxcolumn中的某一项,如何保存到数据库中?
- 最近我在用MS agent开发一个语音控制的软件,但。。。?
- 在c#的windows应用程序中,怎样实现在datagrid中增加空行,并能在其中某一列插入一设定的值
- 大家帮我看看这个问题
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace _000302
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
public System.Data.SqlClient.SqlConnection sqlConnection1;
public System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
public System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
public System.Windows.Forms.DataGrid dataGrid1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
public _000302.DataSet3 dataSet31;
/// <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 Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet31 = new _000302.DataSet3();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet31)).BeginInit();
this.SuspendLayout();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "initial catalog=00030224;integrated security=SSPI;persist security info=False;wor" +
"kstation id=ZY;packet size=4096";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "TABLE2", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("xxx", "xxx"),
new System.Data.Common.DataColumnMapping("zzz", "zzz")})});
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO TABLE2(xxx, zzz) VALUES (@xxx, @zzz); SELECT xxx, zzz FROM TABLE2";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@xxx", System.Data.SqlDbType.VarChar, 10, "xxx"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@zzz", System.Data.SqlDbType.VarChar, 10, "zzz"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT xxx, zzz FROM TABLE2";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 272);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(184, 272);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
//
// dataGrid1
//
this.dataGrid1.DataMember = "TABLE2";
this.dataGrid1.DataSource = this.dataSet31;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(80, 80);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(312, 152);
this.dataGrid1.TabIndex = 4;
this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
//
// dataSet31
//
this.dataSet31.DataSetName = "DataSet3";
this.dataSet31.Locale = new System.Globalization.CultureInfo("zh-CN");
this.dataSet31.Namespace = "http://www.tempuri.org/DataSet3.xsd";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(512, 365);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.dataGrid1,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
} private void Form1_Load(object sender, System.EventArgs e)
{ this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(this.dataSet31);
this.sqlConnection1.Close();
Form2 form2=new Form2();
form2.Show();
} private void comboBox1_SelectionChangeCommitted(object sender, System.EventArgs e)
{
} private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace _000302
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Windows.Forms.DataGrid dataGrid1;
public string x=null;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private _000302.DataSet21 dataSet211;
private System.Windows.Forms.TextBox textBox1;
public string s1=null;
public string s=null;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private Form1 form1; public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
form1=new Form1(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet211 = new _000302.DataSet21();
this.textBox1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet211)).BeginInit();
this.SuspendLayout();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "initial catalog=00030224;integrated security=SSPI;persist security info=False;wor" +
"kstation id=ZY;packet size=4096";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "供应材料", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("供应商", "供应商"),
new System.Data.Common.DataColumnMapping("材料名称", "材料名称")})});
//
// dataGrid1
//
this.dataGrid1.DataMember = "供应材料";
this.dataGrid1.DataSource = this.dataSet211;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(80, 48);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ReadOnly = true;
this.dataGrid1.Size = new System.Drawing.Size(256, 160);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.Click += new System.EventHandler(this.dataGrid1_Click);
this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 供应商, 材料名称 FROM 供应材料";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 供应材料(供应商, 材料名称) VALUES (@供应商, @材料名称); SELECT 供应商, 材料名称 FROM 供应材料";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@供应商", System.Data.SqlDbType.VarChar, 10, "供应商"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@材料名称", System.Data.SqlDbType.VarChar, 10, "材料名称"));
//
// dataSet211
//
this.dataSet211.DataSetName = "DataSet21";
this.dataSet211.Locale = new System.Globalization.CultureInfo("zh-CN");
this.dataSet211.Namespace = "http://www.tempuri.org/DataSet21.xsd";
//
// textBox1
//
this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet211, "供应材料.供应商"));
this.textBox1.Location = new System.Drawing.Point(120, 240);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(504, 325);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox1,
this.dataGrid1});
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet211)).EndInit();
this.ResumeLayout(false); }
#endregion private void Form2_Load(object sender, System.EventArgs e)
{
this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(this.dataSet211);
this.sqlConnection1.Close();
} private void dataGrid1_Click(object sender, System.EventArgs e)
{
//string s1=this.dataSet211.供应材料.
//string s2=this.dataSet211.供应材料
DataTable t=this.dataSet211.供应材料;
string s=t.Rows[0]["供应商"].ToString();
MessageBox.Show(s);
} private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
int n;
n=0;
DataTable t=this.dataSet211.供应材料;
n=this.dataGrid1.CurrentCell.RowNumber;
string s=t.Rows[n]["供应商"].ToString();
string s1=t.Rows[n]["材料名称"].ToString();
MessageBox.Show(s);
MessageBox.Show(s1);
//Form1 form1=new Form1();
form1.sqlConnection1.Open();
form1.sqlDataAdapter1.Fill(form1.dataSet31);
form1.sqlConnection1.Close();
DataTable dt=form1.dataSet31.TABLE2;
DataRow myrow=dt.NewRow();
myrow["xxx"]=s;
myrow["zzz"]=s1;
dt.Rows.Add(myrow);
//Form1 form1=form1.Activate();
//form1.Show();
form1.dataGrid1.SetDataBinding(form1.dataSet31,form1.dataSet31.TABLE2.ToString());
//form1.sqlConnection1.Open();
// form1.sqlDataAdapter1.Fill(form1.dataSet31);
//form1.sqlConnection1.Close();
// form1.dataGrid1.Refresh();
//this.dataGrid1.SetDataBinding(form1.dataSet31,form1.dataSet31.TABLE2.ToString());
}
}
}
transfer form1's object as a parameterform2 f =new form2(form1's object) ;
public Form form1Handl;
public form2(Form f){ this.form1Handl=f; }//构造函数
//就可以在form2中控制form1了!在form1中的button_click事件中:
form2 f2=new form2(this);
f2.show;
传参,各种类型的定义极其使用就很方便解决你这个问题! wish u good luck
Greatsft
如
private pform1;
form2(form1 pform1)
{this.pform1=pform1}
之后要调用form1时用
this.pform1.show(); 就行了,调别的函数也可以
但是我还是建议你抽空学习一下C#的基础部分。
重写Form2的构造函数
private Form pForm1;
public Form2()
{
}
public Form2(Form1 pform1)
{
InitializeComponent();
this.pForm1=pform1;/*这里把在Form2内部定义的pForm1 引用为Form1类型的变量pform1*/
}
明白没有?
有关调用实时 (JIT) 调试而不是此对话框的详细信息,
请参阅此消息的结尾。************** 异常文本 **************
System.MissingMethodException: 找不到方法:Void _000302.Form2._Deleted()。
at _000302.Form1.Form1_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** 已加载的程序集 **************
mscorlib
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/winnt/microsoft.net/framework/v1.0.3705/mscorlib.dll
----------------------------------------
000302
程序集版本:1.0.1566.898
Win32 版本:1.0.1566.898
基本代码:file:///F:/Visual%20Studio%20Projects/000302/bin/Debug/000302.exe
----------------------------------------
System.Windows.Forms
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/winnt/assembly/gac/system.windows.forms/1.0.3300.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/winnt/assembly/gac/system/1.0.3300.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/winnt/assembly/gac/system.drawing/1.0.3300.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Data
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/winnt/assembly/gac/system.data/1.0.3300.0__b77a5c561934e089/system.data.dll
----------------------------------------
System.Xml
程序集版本:1.0.3300.0
Win32 版本:1.0.3705.0
基本代码:file:///c:/winnt/assembly/gac/system.xml/1.0.3300.0__b77a5c561934e089/system.xml.dll
----------------------------------------
mscorlib.resources
程序集版本:1.0.3300.0
Win32 版本:1.0.3300.0
基本代码:file:///c:/winnt/assembly/gac/mscorlib.resources/1.0.3300.0_zh-chs_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
程序集版本:1.0.3300.0
Win32 版本:1.0.3300.0
基本代码:file:///c:/winnt/assembly/gac/system.windows.forms.resources/1.0.3300.0_zh-chs_b77a5c561934e089/system.windows.forms.resources.dll
----------------------------------------************** JIT 调试 **************
若要启用实时 (JIT) 调试,此
应用程序或计算机的配置文件 (machine.config) 的
system.windows.forms 节中必须设置 jitDebugging 值。
编译应用程序时还必须启用
调试。例如:<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>启用 JIT 调试后,任何未处理的异常
将被发送到此计算机上注册的 JIT 调试器,
而不是由此对话框处理。
我看了上面几位的说法,我知道了,就是要在FORM2里重新写构造函数,并且通过这个改造函数把FORM1给引用进来,然后在FORM2里就可以直接调用FORM1了,这个我理解了。
但是又有了一个新的问题,我在Form1里面肯定要有一个打开Form2的,所以我这样写:
Form2 form2=new Form2(); //重载“Form2”方法未获取“0”参数
form2.Show();
这样好象没问题吧?
//////////
但是出了新的问题:
重载“Form2”方法未获取“0”参数----------------------------
一般来说是不会有这个问题的,是不是因为在FORM2里引用了FORM1,然后导致了就不可以这样打开FORM2了呢?????????????????
//////
然后我又想,在FORM1里面把FORM2也引用过来好了,但是又有了一个问题,
在主窗体中,Form1中:
static void Main()
{
Application.Run(new Form1());//这里有问题, 重载“Form1”方法未获取“0”参数 }
---------------------重载“Form1”方法未获取“0”参数
/////////////////
我又不知道怎么办了,各位请帮忙,多谢了,不过现在我已经知道懂了一些了,很高兴,谢谢,请继续帮我看看吧。。
我是用你的办法啊,应该没什么错误的,完全按你那样写的
你是想先生成一个Form1,然后生成Form2,在Form2里面操作从而改变Form1吧?
你的这一段代码
Form2 form2=new Form2(); //重载“Form2”方法未获取“0”参数
form2.Show();
好象不对哦。应该使用重写的构造函数。
Form1 form1=new Form1();
Form2 form2=new Form2(form1);
form2.Show();
form2.Show();
好象不对哦。应该使用重写的构造函数。
Form1 form1=new Form1();
Form2 form2=new Form2(form1);
form2.Show();
/////////////
哎,对啊,我有点笨了,FORM2的构造函数都已经改变了嘛,当然不可以再像以前那样使用了,明白了,现在算是把这个问题解决了95%了,所以非常感谢上面的兄弟,爱死你了,哎,不过由于这个又搞出了一个新的问题,不过问题不大了,你现在可能睡了吧,什么时候你有空看到了再给我说说好吧
是这样的:(发现问题还不是太小哦)
在Form1中:(要先打开Form2)
1:Form1 form1=new Form1();
2:Form2 form2=new Form2(form1);
3:form2.Show();//这里搞完以后就有两个窗体显示出来了,FORM1,FORM2,如果不HIDE FORM1的话,也不应该HIDE,负责以后也不行
然后在Form2中://使FORM1中的数据变了,然后显示Form1
4:form1.show();//这里完了以后又有了一个FORM1了,到这里就有1+1=2个FORM1了
///////语句都没什么问题,但是好象又回到以前了,
就这样,每执行一下3,就让FORM2多了一个版本,
每执行一下4,就让FORM1多了一个版本
最后就N个FORM2和FORM1的窗体了,
好象和我最开始说的问题一样了,而没达到一个真真的引用的效果,也就是说,始终都只有一个FORM1和一个FORM2,(而HIDE 是不行的,)按道理说应该只有一个的,要不你在你自己机器上搞一下看看,呵呵,麻烦你继续帮我弄啊,郁闷死了
哎,自己搞错了,
在Form1中:(要先打开Form2)
1:Form1 form1=new Form1();
2:Form2 form2=new Form2(form1);
3:form2.Show();//
改一下就好了:
Form2 form2= new Form2(this);
form2.Show();
////
其实上面的LIJUN84已经说过了,只是他写得感觉好象有点乱(主要我差),当时没看清楚
但是又有一个最后一个新的问题,我想这对我来说是最后一个问题了
就是FORM2里确实可以正确引用FORM1了,但是在FORM1里还不可以引用FORM2啊,因为FORM1是爷爷啊,它不可以引用他的儿子啊,这样
Form2 form2= new Form2(this);
form2.Show();
就导致了N个FORM2了,除非每次在FORM2中打开FORM1的时候就关了FORM2,但是如果我不想关呢,希望就在这两个FORM中搞来搞去的,怎么办,呵呵,等待帮助了,我不懂了,晕死,自卑中(不过这个问题不大了,如果不的,就每次CLOSE了,但是有时候可能给用户带来不方便,因为可能希望两个FORM都显示出来,可以看两个的信息)
如果你的Form1,Form2都是在Main里面实例化的,你也可以用一种比较变通的办法
Form1里面加一个
public Form2 m_fm2;
Form2可以照以前那么做
然后实例化的时候可以
Form1 fm1 = new Form1();
Form2 fm2 = new Form2(fm1);
fm1.m_fm2 = fm2;
呵呵,这样就可以引用fm2了,当然如果出于封装考虑应该是private+方法,这里仅仅是说一下思路
你用的Form2 form2 = new Form2(this);
这个form2不就是你需要引用的form2么?为什么还要new?楼主似乎已经困晕了……
这样好象不得啊,如果这样的话,还是会出现新的FORM2窗体的,
///
再如果按你上面的方法的话,也就是说在MAIN里面实例化FORM1和FORM2的话,在BUTTON按钮中事件里form2.show(),这样就出现了异常,是form2.show()这句话的问题。你再看看我搞错了没有
http://www.csdn.net/Develop/read_article.asp?id=26433
http://www.csdn.net/Develop/read_article.asp?id=26434
http://www.csdn.net/Develop/read_article.asp?id=26436