Form2 f2 = new Form2(); private void button1_Click(object sender, EventArgs e) { f2.MyA+= new Form2.AA(B); f2.Show(); } void B(string str){}public delegate void AA(string str); public event AA MyA; private void button1_Click(object sender, EventArgs e) { this.MyA(); }
//Form1 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace TestShow { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public Form1(string str) { InitializeComponent(); this.label1.Text = str; } private void button2_Click(object sender, EventArgs e) { Form2 fr2 = new Form2(); fr2.Show(); this.Visible = false; } //========================= //Form2 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace TestShow { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form1 fr1 = new Form1(textBox1.Text); fr1.Show(); this.Visible = false; } } }
伪代码//form1 public set(int a) { //here you can set this form,such as this.width=a; }// in another function form2 f2=new form2(); f2.tag=this; f2.show(); //--------- //form2form1 f1=(form1)this.tag; f1.set(50);
Form2 f2 = new Form2();
private void button1_Click(object sender, EventArgs e)
{
f2.MyA+= new Form2.AA(B);
f2.Show();
}
void B(string str){}public delegate void AA(string str);
public event AA MyA;
private void button1_Click(object sender, EventArgs e)
{
this.MyA();
}
//Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TestShow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(string str)
{
InitializeComponent();
this.label1.Text = str;
}
private void button2_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
fr2.Show();
this.Visible = false;
}
//=========================
//Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TestShow
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 fr1 = new Form1(textBox1.Text);
fr1.Show();
this.Visible = false;
}
}
}
public set(int a)
{
//here you can set this form,such as
this.width=a;
}// in another function
form2 f2=new form2();
f2.tag=this;
f2.show();
//---------
//form2form1 f1=(form1)this.tag;
f1.set(50);