所以,我对C#编程很陌生,我有一个朋友帮帮我。他制作了这段代码:
private void Form1_Shown(object sender, EventArgs e)
{
System.Timers.Timer t = new System.Timers.Timer(50);
t.Elapsed += t_Elapsed;
t.Start();
}
void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
((System.Timers.Timer)sender).Stop();
DisplayOrder();
}
用于在短时间内暂停程序,然后重置"重置"。
在evnthandler本身的正上方,它在" label_Click"中使用。事件处理程序:
System.Timers.Timer t = new System.Timers.Timer(500);
t.Elapsed += t_Elapsed;
t.Start();
答案 0 :(得分:1)
创建一个计时器t
,它将每隔50ms调用一次处理程序(t_Elapsed
)。然后处理程序将禁用计时器并调用DisplayOrder
- 这意味着只需调用一次处理程序。
基本上,它在调用DisplayOrder
之前等待50ms。你可能会这样做:
private async void Form1_Shown(object sender, EventArgs e)
{
await Task.Delay(50);
DisplayOrder();
}
答案 1 :(得分:0)
private void Form1_Shown(object sender, EventArgs e) // Shown is an event that occurs when the form is first shown
{
System.Timers.Timer t = new System.Timers.Timer(50); // This creates a new timer with an interval of 50 ms
t.Elapsed += t_Elapsed; // The timer is assigned event for when the interval has elapsed - when
// started the, the elapsed event will occur when the given interval
// has elapsed (in this case 50ms)
t.Start(); // Starts the timer
}