Long pressed button
UPDATED: Shortest way:
Using Anonymous Methods
and Object Initializer
:
public void Repeater(Button btn, int interval)
{
var timer = new Timer {Interval = interval};
timer.Tick += (sender, e) => DoProgress();
btn.MouseDown += (sender, e) => timer.Start();
btn.MouseUp += (sender, e) => timer.Stop();
btn.Disposed += (sender, e) =>
{
timer.Stop();
timer.Dispose();
};
}