以下代码实现 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();
}
}



参考:http://www.wxzzz.com/?id=12

相关文章:

  • 2022-12-23
  • 2021-11-04
  • 2021-12-29
  • 2021-09-17
  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
猜你喜欢
  • 2021-09-25
  • 2021-07-26
  • 2021-08-08
  • 2021-06-29
  • 2022-12-23
相关资源
相似解决方案