这样的陷阱问题怎么解决??? Form1.cs{Form2 f2 = new Form2();}Form2.cs{Form1 f1 = new Form1();}这样的陷阱问题怎么解决??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Form1.cs{Form2 f2 = new Form2(this);}Form2.cs构造函数里:Form2(Form1 obj){this.Form=obj;obj.Form=this;} 这个方法好象不行,this.Form是什么意思? 你在form1和form2里便定义一个变量form通过form这样子引用对方 Form1.csusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace CTest{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private Form2 Form; /// <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 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(82, 123); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(128, 21); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.textBox1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { Form2 f = new Form2(this); this.Form =f; f.Show(); this.textBox1.Text=""; } private void textBox1_TextChanged(object sender, System.EventArgs e) { this.Form.Text=this.textBox1.Text; } }} Form2.cs:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace CTest{ /// <summary> /// Form2 的摘要说明。 /// </summary> public class Form2 : System.Windows.Forms.Form { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; private System.Windows.Forms.TextBox textBox1; private Form1 Form; public Form2() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } public Form2(Form1 obj) { this.Form =obj; this.InitializeComponent(); } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(86, 123); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(120, 21); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // Form2 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.textBox1); this.Name = "Form2"; this.Text = "Form2"; this.Load += new System.EventHandler(this.Form2_Load); this.ResumeLayout(false); } #endregion private void textBox1_TextChanged(object sender, System.EventArgs e) { this.Form.Text=this.textBox1.Text; } private void Form2_Load(object sender, System.EventArgs e) { this.textBox1.Text=""; } }} 求教 用户'test'登录失败。(c# winform编程 sql2005) 急,js 限制 text 的输入!!! 关于ListView的简单问题 C# 生成"物料编码"怎么实现! 可否在类间将参数按引用传递? 这个项目经理我应该当吗??? 图片处理的一个问题 如何轮询泛型集合 求Farpoint spread Web for vs2005!!!!! 高手请进,如何在DataGrid 中添加Button ?高分相送! sos!紧急求助,请问如何在web-form里面双击datagrid的一个行,然后就可以得到那个行的某一列的值???在线等,非常着急要啊! excel的基本问题,先来先送分啦
{
Form2 f2 = new Form2(this);
}Form2.cs
构造函数里:Form2(Form1 obj)
{
this.Form=obj;
obj.Form=this;
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace CTest
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private Form2 Form;
/// <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 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(82, 123);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
Form2 f = new Form2(this);
this.Form =f;
f.Show();
this.textBox1.Text="";
} private void textBox1_TextChanged(object sender, System.EventArgs e)
{
this.Form.Text=this.textBox1.Text;
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace CTest
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.TextBox textBox1;
private Form1 Form; public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
public Form2(Form1 obj)
{
this.Form =obj;
this.InitializeComponent();
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(86, 123);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(120, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false); }
#endregion private void textBox1_TextChanged(object sender, System.EventArgs e)
{
this.Form.Text=this.textBox1.Text;
} private void Form2_Load(object sender, System.EventArgs e)
{
this.textBox1.Text="";
}
}
}