Длительное нажатие на кнопку мышкой - C#
Формулировка задачи:
надо, чтобы при нажатии на кнопку в форме, продолжало выполнятся button1_Click...
Решение задачи: «Длительное нажатие на кнопку мышкой»
textual
Листинг программы
public Form1()
{
InitializeComponent();
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.button1_MouseUp);
this.button1.Click += new System.EventHandler(this.button1_Click);
timer1.Interval = 77;
}
int i;
private void button1_Click(object sender, EventArgs e)
{
// здесь твой код. Например этот
++i;
this.Text = i.ToString();
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
timer1.Enabled = true;
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
timer1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
button1.PerformClick();
}