form1窗口
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public event EventHandler name;
private Form2 form2 = new Form2();
private void button1_Click(object sender, EventArgs e)
{
Form2.name = textBox1.Text.Trim();
if (Form2.oldname != Form2.name)
{
name += new EventHandler(Form1_name);
if (name != null)
{ Form1_name(this, e); }
}
Form2.oldname = textBox1.Text.Trim();
}
void Form1_name(object sender, EventArgs e)
{
form2.treeView1.Nodes.Add(Form2.name);
form2.Show();
}
}
form2窗口
public partial class Form2 : Form
{
static public string oldname = string.Empty;
static public string name=string.Empty;
public Form2()
{
InitializeComponent();
}
}