1
C# 및 WPF를 처음 사용합니다. 나는 시간이 약 10 배의 캔버스에 도형을 이동해야 위의 완료 후,레이블 및 움직이는 모양 표시
표시 몇 레이블을 하나씩 정확히 5 초 후에
을 : 나는 다음을 수행 할 각 이동 사이에 5 초의 갭,
위의 작업을 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(); } }
그러나 문제 : 다음은
모두 타이머가 동시에 출발 시간 예약.
레이블이 차례대로 표시되지 않습니다. 테스트가 나타나고 5 초 후 bye가 표시됩니다. 안녕하세요!
타이머를 재설정하고 위에서 언급 한 Shapemove 또는 startDisplay 함수처럼 반복적으로 함수로 호출 할 수 있습니까?
친절하게도 위의 문제를 해결하는 데 도움이됩니다.