/// <summary>
/// Flashes the control.
/// </summary>
/// <param name="control"></param>
/// <param name="spanOff"></param>
public static void Blink( [CanBeNull] this Control control, [CanBeNull] TimeSpan? spanOff = null ) {
if ( null == control ) {
return;
}
if ( !spanOff.HasValue ) {
spanOff = 333;
}
control.OnThread( () => {
var foreColor = control.ForeColor;
control.ForeColor = control.BackColor;
control.BackColor = foreColor;
control.Refresh();
} );
var timer = new Timer { AutoReset = false, Interval = spanOff.Value.TotalMilliseconds };
timer.Elapsed += ( sender, args ) => {
control.OnThread( () => {
control.ResetForeColor();
control.ResetBackColor();
control.Refresh();
} );
using ( timer ) { timer = null; }
};
GC.KeepAlive( timer );
timer.Start();
}
No comments:
Post a Comment