12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 录屏等待 CountdownWindow.xaml 的交互逻辑
- /// </summary>
- public partial class CountdownWindow : Window
- {
- public CountdownWindow(int changeTime = 650)
- {
- InitializeComponent();
- timer = new System.Timers.Timer(changeTime);//设置执行一次(false)还是一直执行(true)
- timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
- timer.Elapsed +=new System.Timers.ElapsedEventHandler(Timer_Elapsed);
- Initialize();
- }
- /// <summary>
- /// 计时器
- /// </summary>
- new System.Timers.Timer timer;
- int ImgNum = 3;
- public void Initialize(int changeTime=650)
- {
- timer.Interval = changeTime;
- timer.Enabled = true; //启动计时器
- ImgNum = 3;
- }
-
- private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (ImgNum >= 1)
- {
- loadingImg(ImgNum);
- ImgNum--;
- }
- else
- {
- timer.Enabled = false;
- Dispatcher.Invoke(() =>
- {
- Hide();
- });
- }
- }
- /// <summary>
- /// 加载图片
- /// </summary>
- /// <param name="num"></param>
- void loadingImg(int num)
- {
- switch (num)
- {
- case 1:
- Dispatcher.Invoke(
- DispatcherPriority.Send,
- new Action(() => {
- imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png"));
- }));
- break;
- case 2:
- Dispatcher.Invoke(
- DispatcherPriority.Send,
- new Action(() => {
- imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
- }));
- break;
- case 3:
- Dispatcher.Invoke(
- DispatcherPriority.Send,
- new Action(() => {
- imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_3.png"));
- }));
- break;
- default:
- break;
- }
- }
-
- private void Window_ContentRendered(object sender, EventArgs e)
- {
-
- }
-
- }
- }
|