星火微课系统客户端
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.0KB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. new 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. //_state = State.End;
  49. Dispatcher.Invoke(
  50. DispatcherPriority.Normal,
  51. new Action(() => { this.Hide(); imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_3.png")); })
  52. );
  53. }
  54. /// <summary>
  55. /// 加载图片
  56. /// </summary>
  57. /// <param name="num"></param>
  58. void loadingImg(int num)
  59. {
  60. switch (num)
  61. {
  62. case 1:
  63. Dispatcher.Invoke(
  64. DispatcherPriority.Send,
  65. new Action(() => {
  66. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png"));
  67. }));
  68. break;
  69. case 2:
  70. Dispatcher.Invoke(
  71. DispatcherPriority.Send,
  72. new Action(() => {
  73. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
  74. }));
  75. break;
  76. case 3:
  77. Dispatcher.Invoke(
  78. DispatcherPriority.Send,
  79. new Action(() => {
  80. imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_3.png"));
  81. }));
  82. break;
  83. default:
  84. break;
  85. }
  86. }
  87. private void Window_ContentRendered(object sender, EventArgs e)
  88. {
  89. }
  90. }
  91. }