以下代码实现 B窗体调用A窗体的方法。
其实就是传 this
窗体A:
public partial class FormA : Form
{
public FormA()
{
InitializeComponent();
}
public void AAA()
{
MessageBox.Show("来自A窗体的方法");
}
private void button1_Click(object sender, EventArgs e)
{
FormB bFrm = new FormB(this);
bFrm.Show();
}
}
窗体B:
public partial class FormB : Form
{
FormA aFrm;
public FormB(FormA frm)
{
InitializeComponent();
this.aFrm = frm;
}
private void button1_Click(object sender, EventArgs e)
{
this.aFrm.AAA();
}
}