Click here to Skip to main content
14,699,811 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Application in which i required that timer of form3 strat when i click button of form1 to open a form2 . Here is my code :

What I have tried:

from3.timerrefresh ;
                 private void btnbreak_Click(object sender, EventArgs e)

                 from2 fm= new from2 ();
                 fm.timerrefresh = timerdatarefresh;
                 fm.TopLevel = true;

Updated 29-Oct-20 3:54am
Member 14852747 29-Oct-20 7:22am
Can i get timer1 of form1 in form2 load event?

Create a public method in Form3 which starts the timer, and call it from Form1 before you call this:

However, it probably won't do what you want it to, because ShowDialog is application modal: it doesn't return until the form is closed. So there is a good chance that the instance of Form3 will not update on timer Tick events until the instance of Form2 has been closed. Depends what you are trying to achieve.

You may need to use fm.Show instead, and manually ignore user inputs to Form1 until the Form2 instance has been closed.
Your description is not clear; describe the purpose of each Form. Is Form1 the Main Form ? When is Form3 created and shown ?

When you create Form2 inside an event handler: outside the scope of the event handler it does not exist. Since other Forms don't have a reference to it, then, no other Form can possibly interact with it. Since it has no references to other Forms, it cannot interact with them,

When you show Form2 with ShowDialog, it is a top-level Window.

Try to explain what you wish to achieve clearly,

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