星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CountdownWindow.xaml.cs 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using System;
  2. using System.Threading;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media.Imaging;
  6. using System.Windows.Threading;
  7. namespace XHWK.WKTool
  8. {
  9. /// <summary>
  10. /// 录屏等待 CountdownWindow.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class CountdownWindow : Window
  13. {
  14. public CountdownWindow(int changeTime = 650)
  15. {
  16. InitializeComponent();
  17. timer = new System.Timers.Timer(changeTime);//设置执行一次(false)还是一直执行(true)
  18. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  19. timer.Elapsed +=new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  20. Initialize();
  21. }
  22. /// <summary>
  23. /// 计时器
  24. /// </summary>
  25. System.Timers.Timer timer;
  26. int ImgNum = 9;
  27. public void Initialize(int changeTime=650)
  28. {
  29. timer.Interval = changeTime/3;
  30. timer.Enabled = true; //启动计时器
  31. ImgNum = 9;
  32. }
  33. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  34. {
  35. if (ImgNum >= 1)
  36. {
  37. loadingImg(ImgNum);
  38. ImgNum--;
  39. }
  40. else
  41. {
  42. timer.Enabled = false;
  43. Dispatcher.Invoke(
  44. DispatcherPriority.Send,
  45. new Action(() =>
  46. {
  47. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown3_3.png"));
  48. Hide();
  49. }));
  50. }
  51. }
  52. /// <summary>
  53. /// 加载图片
  54. /// </summary>
  55. /// <param name="num"></param>
  56. void loadingImg(int num)
  57. {
  58. switch (num)
  59. {
  60. case 1:
  61. Dispatcher.Invoke(
  62. DispatcherPriority.Send,
  63. new Action(() => {
  64. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown1_1.png"));
  65. }));
  66. break;
  67. case 2:
  68. Dispatcher.Invoke(
  69. DispatcherPriority.Send,
  70. new Action(() => {
  71. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown1_2.png"));
  72. }));
  73. break;
  74. case 3:
  75. Dispatcher.Invoke(
  76. DispatcherPriority.Send,
  77. new Action(() => {
  78. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown1_3.png"));
  79. }));
  80. break;
  81. case 4:
  82. Dispatcher.Invoke(
  83. DispatcherPriority.Send,
  84. new Action(() => {
  85. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown2_1.png"));
  86. }));
  87. break;
  88. case 5:
  89. Dispatcher.Invoke(
  90. DispatcherPriority.Send,
  91. new Action(() => {
  92. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown2_2.png"));
  93. }));
  94. break;
  95. case 6:
  96. Dispatcher.Invoke(
  97. DispatcherPriority.Send,
  98. new Action(() => {
  99. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown2_3.png"));
  100. }));
  101. break;
  102. case 7:
  103. Dispatcher.Invoke(
  104. DispatcherPriority.Send,
  105. new Action(() => {
  106. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown3_1.png"));
  107. }));
  108. break;
  109. case 8:
  110. Dispatcher.Invoke(
  111. DispatcherPriority.Send,
  112. new Action(() => {
  113. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown3_2.png"));
  114. }));
  115. break;
  116. case 9:
  117. Dispatcher.Invoke(
  118. DispatcherPriority.Send,
  119. new Action(() => {
  120. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown3_3.png"));
  121. }));
  122. break;
  123. default:
  124. break;
  125. }
  126. }
  127. private void Window_ContentRendered(object sender, EventArgs e)
  128. {
  129. }
  130. }
  131. }