Click here to Skip to main content
15,887,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have form1(parent) and form2(Child) both are open . I want to start timer of form1(parent) from from2(Child) .How can i do that . what i have tried is with public function

          
with this method timer1 does not work . anyone can help me


What I have tried:

**form2 code**

          from1 frm = new from1 ();
          frm.callmethod();


          **form1 code**
          private void statuscheckin()
          {
            timer1.Start();
          }
          public void getdetailofcheckin()
          {
          statuscheckin();
          }
Posted
Updated 11-Nov-20 0:37am
Comments
F-ES Sitecore 11-Nov-20 6:40am    
You should use events for this. The child form should have some kind of "StartTimer" event that the parent form subscribes to. The child form will raise this event when required and the parent form will then start the timer when the event is raised. Google for how to use events for specific implementation details.
BillWoodruff 11-Nov-20 8:11am    
If 'Form1 is the "parent:" why are you creating it in Form 2 ?

Is this a WinForm app: what is the Main Form ?

That code won't even compile. Firstly it should be
C#
form1 frm = new form1 ();
Next, you have no method in form1 called callmethod()Then the method to start the timer in form1 is private instead of public
Try form2 code:
C#
form1 frm = new form1();
frm.getdetailofcheckin();
 
Share this answer
 
Comments
Member 14852747 11-Nov-20 13:18pm    
actully i'm calling getdetailofcheckin on form1!
CHill60 11-Nov-20 13:35pm    
Not according to the code you posted. Remember I can't see your screen, access your HDD nor read your mind! What am I supposed to think when you post
frm.callmethod();
If it still doesn't work and you can prove by using the debugger that the method is being called correctly then check that the timer has been enabled and all properties are correctly set.
See here: Transferring information between two forms, Part 2: Child to Parent[^]

Raise the event, the Parent form handles it, and it deals with it's own timer.
 
Share this answer
 
Comments
CHill60 11-Nov-20 8:16am    
Unlike me not to have quoted that Tip! 5'd

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900