handle forms using timers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kayo
    New Member
    • Oct 2011
    • 4

    handle forms using timers

    i need to run a form in the background(Main ),on top of that another form(Main1) runs.
    when Main1 loads it should wait for 10 seconds and direct to another form(bpaper) if the system time is less than 4.00 p.m
    if the system time is greater than 4.00 p.m then it should remain in the Main1
    how can i do this using a timer?
    (Main forms' isMdiContainer is true!)


    form load of Main
    Code:
    Main1 one = new Main1();
    one.MdiParent = Main.ActiveForm;
    one.Show();


    form load of Main1
    Code:
    timer1.Start();
    timer1.wait(1000);  //how can i wait the timer here?
    
    t1 = DateTime.Now;            
    t2 = Convert.ToDateTime("16:00:00 ");
    bpaper test = new bpaper();
    
    
    //do not allow the bpaper to be appear after 4oclock
    if (t1<t2)  
           {            
            timer1.Stop();
            this.Hide();
            test.Show();
            }
    else
            {
               timer1.Stop();
               this.Show();               
               MessageBox.Show("Time out ",t1.ToString());
            }
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    Looking at your code, why do you need the timer to wait? Just set the interval to whatever tick rate you want and the Tick event will occur on that interval. Other than that, the general idea of your code looks fine. In the Tick event, check the time and take the appropriate action.

    My apologies if I'm not understanding your problem correctly. If this is the case, can you please be more descriptive?

    Comment

    • kayo
      New Member
      • Oct 2011
      • 4

      #3
      i need to run the timer for 10seconds.withi n that time it should check the t1 and t2 values.
      if t1<t2 ---->current form(Main1) should hide.
      otherwise remain in the same form(Main1)
      can u please help me to construct the code for this purpose.


      should i set interval to 10sec?
      how to occur the tick event in the interval?
      tick event must have the t1 N t2 comparisons and relevant form actions

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Read up on the Timer class. That page contains all the properties and methods you can access, as well as an example at the bottom.

        So yes, you can set your interval to 10 seconds. The interval is actually in milliseconds, so you would set it to 10000. Then put your comparison code in the Elapsed method. This used to be called Tick, so you might be able to use that too but it doesn't matter, they mean the same thing.

        Inside that event, you can do your comparison, then take the appropriate actions. Give the coding a try and if you have troubles, post back here and I'll try to help you through it.

        Comment

        Working...