首页 > 解决方案 > 闪光次数有限的定时器

问题描述

启动表单时,我需要计时器闪烁 8 次:“按 OK 按钮”并停止闪烁。上网搜索,但没有找到。我试着写了一个循环,但还是不明白怎么写。你能写一个计时器并解释它是如何工作的吗?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Start();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            int w = (int)this.button1.Size.Width;
            int h = (int)this.button1.Size.Height;
            Random r = new Random();
            button1.Left = r.Next(0, this.Size.Width - button1.Width);
            button1.Top = r.Next(0, this.Size.Height - button1.Height);
            this.button1.Size = new System.Drawing.Size(w - 3, h - 3);
            if (button1.Focused)
            {
                this.Text = "Мимо";

            }
            else
            {
                this.Text = "Нажміть на кнопку ОК!!!";
            }
        }
        private int time;

        private void timer1_Tick(object sender, EventArgs e)
        {
         
            this.Text = time.ToString("click OK"); //timer
          
            
            
        }
    }
}



标签: c#winforms

解决方案


推荐阅读