次が必要です: スペースバーを押すと - label1.Text が "Up" になり、数秒後 (1 から 5 までランダム)、label1.Text が "Remove hand" に変わり、次に KeyUp label1.Text が "Down" に変わります。 . KeyUpとKeyDownの使い方はわかるのですが、タイマーの使い方がわかりません???
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Timer timer = new Timer();
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
label1.Text = "Down";
timer.Interval = 5000;//5 seconds
timer.Tick += new EventHandler(timer1_Tick);
timer.Start();
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
label1.Text = "Up";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = "Remove";
timer.Stop();
}
}
}