日期:2014-05-20  浏览次数:20788 次

form1控制form2 怎样实现
新建一个form1里面有一个“打开form2”的按钮

还有一个文本框text1文本框旁有一个“给form2的文本框赋值“,的按钮

新建一个form2     里面只一个文本框text2.

步骤是这样的!
1,程序运行打开form1   点击“打开form2”   就show了from2出,来同时“打开form2”
这个按钮也不可用了。
2   ,接在form1的文本框里输入文本   然后点“赋值”按钮
结果form2里的文本框的值就等于form1里文本框的值了

请问在c#   winform里怎样实这个

只要是怎样把form1里的text1的值传给刚打开的form2里的text2

------解决方案--------------------
我的代码可能帮不了ls
但是差不多参考一下吧
form1
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication16
{
/// <summary>
/// Form1 の概要の説明です。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
public static string sr;
/// <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.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(264, 88);
this.button1.Name = "button1 ";
this.button1.Size = new System.Drawing.Size(88, 56);
this.button1.TabIndex = 0;
this.button1.Text = "button1 ";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(40, 80);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1 ";
this.textBox1.Size = new System.Drawing.Size(136, 56);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "111111111 ";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(384, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1 ";
this.Text = "Form1 ";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
sr=textBox1.Text;
this.Hide();
Form2 fr=new Form2();
fr.Show();
}
}
}


form2 的load
textBox1.Text=Form1.sr;
------解决方案--------------------