123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- namespace XHWK.WKTool
- {
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
-
- /// <summary>
- /// 录屏等待 CountdownWindow.xaml 的交互逻辑
- /// </summary>
- public partial class CountdownWindow
- {
- private readonly List<BitmapImage> _images = new List<BitmapImage>();
-
- public CountdownWindow()
- {
- InitializeComponent();
- foreach (string imgName in _imgNames)
- {
- _images.Add(new BitmapImage(new Uri("pack://application:,,/Images/" + imgName)));
- }
- }
-
- /// <summary>
- /// 计时器
- /// </summary>
- private int _imgNum = 22;
-
- public void InitAndShow(bool showlblShortcut = false, int changeTime = 3000)
- {
- ImgLoding.Source = _images.Last();
- Init(showlblShortcut, changeTime);
- Show();
- }
-
- private System.Timers.Timer _timer;
-
- private async void Init(bool showlblShortcut, int changeTime)
- {
- if (showlblShortcut)
- {
- LblShortcut.Visibility = Visibility.Visible;
- BorShortcut.Visibility = Visibility.Visible;
- }
- else
- {
- LblShortcut.Visibility = Visibility.Hidden;
- BorShortcut.Visibility = Visibility.Hidden;
- }
- _imgNum = 22;
- _timer = new System.Timers.Timer();
- _timer.Enabled = true;
- _timer.Interval = 1.0 * changeTime / 22;
- _timer.Elapsed += Timer_Elapsed;
- _timer.Disposed += _timer_Disposed;
- _timer.Start();
- await Task.Delay(300);
- }
-
- private void _timer_Disposed(object sender, EventArgs e)
- {
- Dispatcher.Invoke(
- async () =>
- {
- // 执行操作
- ImgLoding.Source = null;
- await Task.Delay(300);
- Hide();
- },
- DispatcherPriority.Send
- );
- }
-
- private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (_imgNum >= 0)
- {
- Dispatcher.Invoke(
- () =>
- {
- // 执行操作
- ImgLoding.Source = _images[_imgNum];
- },
- DispatcherPriority.Send
- );
- _imgNum--;
- }
- else
- {
- _timer.Stop();
- _timer.Dispose();
- }
- }
-
- readonly string[] _imgNames =
- {
- "countdown1_7.png",
- "countdown1_6.png",
- "countdown1_5.png",
- "countdown1_4.png",
- "countdown1_3.png",
- "countdown1_2.png",
- "countdown1_1.png",
- "countdown2_7.png",
- "countdown2_6.png",
- "countdown2_5.png",
- "countdown2_4.png",
- "countdown2_3.png",
- "countdown2_2.png",
- "countdown2_1.png",
- "countdown3_8.png",
- "countdown3_7.png",
- "countdown3_6.png",
- "countdown3_5.png",
- "countdown3_4.png",
- "countdown3_3.png",
- "countdown3_2.png",
- "countdown3_1.png",
- "countdown3_1.png",
- };
- }
- }
|