CSkin博客

标题: 新手学习TIMER控件,为何不运行。 [打印本页]

作者: cqwgj_123    时间: 2020-4-27 23:21
标题: 新手学习TIMER控件,为何不运行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;


namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    ///

    public partial class MainWindow : Window
    {
        Timer t1 = new Timer();

        public MainWindow()
        {
            InitializeComponent();

            t1.Interval = 1000;
            t1.Enabled = true;

        }


        private void t1_Tick(object sender, System.EventArgs e)
        {
            t1.Enabled = false;
            MessageBox.Show("需要休息了,开机已经2小时了");
            t1.Enabled = true; //如果不先把timer1设成false,对话框会一直弹下去。

        }
    }
}
作者: 1844653966    时间: 2020-4-28 14:35
这个确定不能启动吗
作者: 乔克斯    时间: 2020-4-28 21:57
t1.Start()
t1.Stop()




欢迎光临 CSkin博客 (http://bbs.cskin.net/) Powered by Discuz! X3.2