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

CountdownWindow.xaml.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 = 3;
  27. public void Initialize(int changeTime=650)
  28. {
  29. timer.Interval = changeTime;
  30. timer.Enabled = true; //启动计时器
  31. ImgNum = 3;
  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. {
  45. Hide();
  46. });
  47. }
  48. }
  49. /// <summary>
  50. /// 加载图片
  51. /// </summary>
  52. /// <param name="num"></param>
  53. void loadingImg(int num)
  54. {
  55. switch (num)
  56. {
  57. case 1:
  58. Dispatcher.Invoke(
  59. DispatcherPriority.Send,
  60. new Action(() => {
  61. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png"));
  62. }));
  63. break;
  64. case 2:
  65. Dispatcher.Invoke(
  66. DispatcherPriority.Send,
  67. new Action(() => {
  68. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
  69. }));
  70. break;
  71. case 3:
  72. Dispatcher.Invoke(
  73. DispatcherPriority.Send,
  74. new Action(() => {
  75. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_3.png"));
  76. }));
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. private void Window_ContentRendered(object sender, EventArgs e)
  83. {
  84. }
  85. }
  86. }