locked
timer for windows app RRS feed

  • Question

  • Hi Guys,

    I want to make a textbox invisible after a few seconds or so, but I can't seem to get it to work:

     void timer_Tick()
             {
                
                 DispatcherTimer timer = new DispatcherTimer();
                
                 timer.Tick += timer_Tick;
                 timer.IsEnabled.Equals(true);  //not sure about this
                 timer.Interval = TimeSpan.FromSeconds(5);
                            
               
             }
             private void timer_Tick(object sender, object e)
             {
                 text1.Visibility = Visibility.Collapsed;
             } 

    any suggestions would be appreciated.

    thanks

    marlon

    Wednesday, December 11, 2013 5:01 PM

Answers

  • You forgot to start the timer. timer.Start()

     private void Button_Click_2(object sender, RoutedEventArgs e)
            {
                DispatcherTimer timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromSeconds(5);
                timer.Tick+=timer_Tick;
                timer.Start();
            }
            private void timer_Tick(object sender, object e)
            {
                text1.Visibility = Visibility.Collapsed;
            } 

    • Proposed as answer by Anne Jing Thursday, December 12, 2013 3:02 AM
    • Marked as answer by marlon_1_1 Thursday, December 12, 2013 3:14 PM
    Wednesday, December 11, 2013 5:32 PM