2012-05-23 2 views
1

C# 및 WPF를 처음 사용합니다. 나는 시간이 약 10 배의 캔버스에 도형을 이동해야 위의 완료 후,레이블 및 움직이는 모양 표시

  1. 표시 몇 레이블을 하나씩 정확히 5 초 후에

  2. 을 : 나는 다음을 수행 할 각 이동 사이에 5 초의 갭,

  3. 위의 작업을 2 초의 시간 간격으로 수행하십시오. 위의와

    DispatcherTimer timer2 = new DispatcherTimer(); 
        float timerTime = 10; 
        Label timerlabel = new Label(); 
    
        private void Window_Loaded(object sender, RoutedEventArgs e) 
        { 
         lbl.Content = "test"; 
         startDisplay("hello!!"); 
         startDisplay("bye"); 
         Shapemove(1); 
        } 
    
        private void startDisplay(string st) 
        { 
         DispatcherTimer timer = new DispatcherTimer(); 
         timer.Interval = TimeSpan.FromSeconds(5); 
         timer.Start(); 
         timer.Tick += (s, e) => 
         { 
          lbl.Content = st; 
         }; 
        } 
    
        private void Shapemove(int i) 
        { 
    
         timer2.Interval = new TimeSpan(0, 0, 2); 
         timer2.Tick += new EventHandler(timer2_Tick); 
         timer2.Start(); 
    
        } 
    
        void timer2_Tick(object sender, EventArgs e) 
        { 
         Random rand = new Random(); 
    
         if (timerTime > 0) 
         { 
          canvas1.Children.Remove(timerlabel); 
          timerTime--; 
    
          canvas1.Children.Add(timerlabel); 
          timerlabel.FontSize = 20; 
          timerlabel.Content = timerTime + "s"; 
          Canvas.SetLeft(rectangle1, rand.Next(640)); 
          Canvas.SetTop(rectangle1, rand.Next(480)); 
         } 
         else 
         { 
          timer2.Stop(); 
         } 
        } 
    

    그러나 문제 : 다음은

코드입니다

  1. 모두 타이머가 동시에 출발 시간 예약.

  2. 레이블이 차례대로 표시되지 않습니다. 테스트가 나타나고 5 초 후 bye가 표시됩니다. 안녕하세요!

  3. 타이머를 재설정하고 위에서 언급 한 Shapemove 또는 startDisplay 함수처럼 반복적으로 함수로 호출 할 수 있습니까?

친절하게도 위의 문제를 해결하는 데 도움이됩니다.

답변

1

타이머를 사용하지 마십시오. 대신 StoryBoards를 사용하십시오.

Storyboard에서 가시성, 불투명도, 위치, ... 컨트롤의 모든 (종속성) 속성을 조작하는 애니메이션을 정렬 할 수 있습니다.

See Animations in this tutorial

관련 문제