0

我的父表单(内存)中有以下代码/函数:

    List<int> ControleList = new List<int>(); 

    private void Controle(int controlenummer){

        ControleList.Add(controlenummer);

        if (ControleList.Count == 2)
        {
            if (ControleLijst[0] == ControleLijst[1])
            {
                MessageBox.Show("They are the same!");
            }
            else
            {
                MessageBox.Show("They don't match...");
            }
            ControleList.Clear();
        }
    }

在我的子表单中,我想使用这个功能,我目前有这个(不起作用):

    private void pcbKaart_Click(object sender, EventArgs e)
    {
        Memory.Controle(Waarde);
    }

所以我想知道我如何仍然可以使用此功能,因为将其设为静态对我不起作用..

提前致谢

4

1 回答 1

2

您指定Form了 ,您也可以:

((Memory)this.Parent).Controle(Waarde);  //or is it _this.Owner_?

而且您将不得不采用父母的方法public

此外,如果出现这种MDI情况,您可以将其更改为:

((Memory)this.MdiParent).Controle(Waarde);
于 2013-06-06T15:29:49.373 回答