星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CountdownWindow.xaml.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media.Imaging;
  4. using System.Windows.Threading;
  5. namespace XHWK.WKTool
  6. {
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. /// <summary>
  11. /// 录屏等待 CountdownWindow.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class CountdownWindow
  14. {
  15. private readonly List<BitmapImage> _images = new List<BitmapImage>();
  16. public CountdownWindow()
  17. {
  18. InitializeComponent();
  19. foreach (string imgName in _imgNames)
  20. {
  21. _images.Add(new BitmapImage(new Uri("pack://application:,,/Images/" + imgName)));
  22. }
  23. }
  24. /// <summary>
  25. /// 计时器
  26. /// </summary>
  27. private int _imgNum = 22;
  28. public void InitAndShow(bool showlblShortcut = false, int changeTime = 3000)
  29. {
  30. ImgLoding.Source = _images.Last();
  31. Init(showlblShortcut, changeTime);
  32. Show();
  33. }
  34. private System.Timers.Timer _timer;
  35. private async void Init(bool showlblShortcut, int changeTime)
  36. {
  37. if (showlblShortcut)
  38. {
  39. LblShortcut.Visibility = Visibility.Visible;
  40. BorShortcut.Visibility = Visibility.Visible;
  41. }
  42. else
  43. {
  44. LblShortcut.Visibility = Visibility.Hidden;
  45. BorShortcut.Visibility = Visibility.Hidden;
  46. }
  47. _imgNum = 22;
  48. _timer = new System.Timers.Timer();
  49. _timer.Enabled = true;
  50. _timer.Interval = 1.0 * changeTime / 22;
  51. _timer.Elapsed += Timer_Elapsed;
  52. _timer.Disposed += _timer_Disposed;
  53. _timer.Start();
  54. await Task.Delay(300);
  55. }
  56. private void _timer_Disposed(object sender, EventArgs e)
  57. {
  58. Dispatcher.Invoke(
  59. async () =>
  60. {
  61. // 执行操作
  62. ImgLoding.Source = null;
  63. await Task.Delay(300);
  64. Hide();
  65. },
  66. DispatcherPriority.Send
  67. );
  68. }
  69. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  70. {
  71. if (_imgNum >= 0)
  72. {
  73. Dispatcher.Invoke(
  74. () =>
  75. {
  76. // 执行操作
  77. ImgLoding.Source = _images[_imgNum];
  78. },
  79. DispatcherPriority.Send
  80. );
  81. _imgNum--;
  82. }
  83. else
  84. {
  85. _timer.Stop();
  86. _timer.Dispose();
  87. }
  88. }
  89. readonly string[] _imgNames =
  90. {
  91. "countdown1_7.png",
  92. "countdown1_6.png",
  93. "countdown1_5.png",
  94. "countdown1_4.png",
  95. "countdown1_3.png",
  96. "countdown1_2.png",
  97. "countdown1_1.png",
  98. "countdown2_7.png",
  99. "countdown2_6.png",
  100. "countdown2_5.png",
  101. "countdown2_4.png",
  102. "countdown2_3.png",
  103. "countdown2_2.png",
  104. "countdown2_1.png",
  105. "countdown3_8.png",
  106. "countdown3_7.png",
  107. "countdown3_6.png",
  108. "countdown3_5.png",
  109. "countdown3_4.png",
  110. "countdown3_3.png",
  111. "countdown3_2.png",
  112. "countdown3_1.png",
  113. "countdown3_1.png",
  114. };
  115. }
  116. }