如何调用从父窗体用户窗体的方法?窗体、方法、用户

2023-09-02 10:33:51 作者:我的痛♀有谁懂

学习C#:

我有一个结构

form1 (splitcontainer)
  userformLeft (button + sub-panel)
    userformDisplay (loaded into panel in userformLeft)
  userformRight

我想在userformDisplay从Form1中(定时器在Form1)执行的方法。

I want to execute a method in userformDisplay from form1 (timer in form1).

和周围的其他方式,让我们说我有公共财产form1.mainTimer,可以 我把它从userFormDisplay像

And the other way around, let's say I have public property form1.mainTimer, can I call it from userFormDisplay like

myLong = this.parent.parent.mainTimer;

或类似的。

推荐答案

一种形式和另...之间进行通信的类似的问题是否附着到事件之一,或呼叫/设定值向/从彼此。这里有几个链接的问题我已经回答在过去,可能有助于理解的关系,这样做的。

Similar problems of communicating between one form and another... whether attaching to "events" of one, or calling / setting values to/from each other. Here are a couple links to questions I've answered to in the past that may help understand the relationships to do so.

Sample 1有明确的步骤创建两种形式的通信后退/来回对方

Sample 2有些相似,但附加到形式之间的事件