form1: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace WindowsFormsApplication5 { public partial class Form1 : Form { public Form1() { InitializeComponent(); //textBox1.Leave += new EventHandler(textBox1_Leave); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string a = textBox1.Text; Form2 frm2 = new Form2(a); frm2.Show(); } } } form2: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace WindowsFormsApplication5 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } public Form2(string a)//重写构造方法 { InitializeComponent(); label1.Text = a; } }
{
set
{
this.label1.Text = value;
}
}然后 Form1:
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.LabelTxt = this.textBox1.Text;
frm.Show(); }
初始化
这样后那个textbox1里的值就为空了
说个简单的,在项目里添加一个类,其中放一个public静态变量,如CurName姓名,
这样,Form1中给姓名赋了值,Form2就可以访问到了
{
this.label1.Text = frm.txt;
}Form1:这样写 public string txt
{
get
{
return this.textBox1.Text;
}
}
private void button1_Click(object sender, EventArgs e)
{ Form2 frm = new Form2();
frm.ShowValue(this);
frm.Show();
}
public delegate void Callback(string str);
public Class Form1()
{
public event Callback Callevent=null;
private void button1_Click(object sender, EventArgs e)
{
Callevent(textBox1.Text);
}
}
public Class Form2()
{ private void button1_Click(object sender, EventArgs e)
{
Form1 child = new Form1();
chil.Callevent += (send) =>
{
textBox1.Text = send;
}; child.Show();
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//textBox1.Leave += new EventHandler(textBox1_Leave);
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
string a = textBox1.Text;
Form2 frm2 = new Form2(a);
frm2.Show(); } }
}
form2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication5
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} public Form2(string a)//重写构造方法
{
InitializeComponent();
label1.Text = a;
}
}
}O(∩_∩)O
要么就是让Label可以访问得到,让Form1能够操作它...属性 就是干这事滴