0

Learning C#:

I have structure of

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

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

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;

or similar.

Justin
  • 82,493
  • 48
  • 216
  • 356
Teson
  • 6,414
  • 7
  • 42
  • 67

2 Answers2

2

yes.. you can do this:

myLong = ((form1)this.parent.parent).mainTimer;
1

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 with explicit steps to create two forms communicating back/forth to each other

Sample 2 somewhat similar, but attaching to events between forms

Community
  • 1
  • 1
DRapp
  • 46,075
  • 12
  • 69
  • 139