记性不好,就写下来。这个问题浪了我不少时间,希望不要再浪费其他人的时间了。

1.FrmParent.cs

 private void Button1_Click(object sender, EventArgs e)
        {
            FrmChild frmChild = new FrmChild();
            frmChild .parentFrm = this;
            frmChild .ShowDialog();
        }

public void TestFunction()
{
MessageBox.show("这个是父窗体的函数");
}

2.FrmChild.cs

Form parentFrm ;

private void Button2_Click(object sender, EventArgs e)
        {
((FrmChild)parentFrm).TestFunction();//在这里调用父窗体函数
}

-----------------------------------------------------------------------
窗体5调用窗体2的函数
父窗体 
form1

               f5 = new Form5();
                //f5.Owner = this;
                f5.F2 = f2;
                f5.Show();
form5
           private Form2 f2;
        public Form2 F2
        {
            set { f2 = value; }
        }
        f2.getdatetime();

相关文章:

  • 2021-09-25
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2022-01-06
  • 2021-10-28
猜你喜欢
  • 2021-11-28
  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2022-03-04
相关资源
相似解决方案