當按鈕被點擊時,我想讓按鈕的顏色在5秒後變成黑色,但我無法讓它工作。我已經將該計時器的時間間隔設置爲5000,並在該屬性中將啓用設置爲true。Visual studio c#timer不起作用
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Start();
button1.BackColor = Color.Black;
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
}
您正在使用什麼定時器裏面?你應該使用windows.Forms.Timer。看起來您已經在設計時添加了它,請確保您想延遲的操作在Tick Event中。 –