Created
July 8, 2013 14:12
-
-
Save peruihkxt/5949153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.Windows.Forms; | |
namespace YourNamespace { | |
class Status : StatusStrip { | |
string defaultResetTo; | |
string resetTo; | |
ToolStripStatusLabel label; | |
ToolStripProgressBar progress; | |
System.Timers.Timer textTimer; | |
System.Timers.Timer progressTimer; | |
double timeToReset; | |
public Status() { | |
label = new ToolStripStatusLabel(); | |
progress = new ToolStripProgressBar(); | |
label.Text = "Ready"; | |
label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; | |
label.Spring = true; | |
progress.Visible = false; | |
this.Items.Add(label); | |
this.Items.Add(progress); | |
defaultResetTo = "Ready"; | |
resetTo = "Ready"; | |
setTextDelegate = new Action<string, bool, string>(SetText); | |
if (!DesignMode) { | |
textTimer = new System.Timers.Timer(2000); | |
textTimer.Elapsed += new System.Timers.ElapsedEventHandler(textTimer_Elapsed); | |
progressTimer = new System.Timers.Timer(2000); | |
progressTimer.Elapsed += new System.Timers.ElapsedEventHandler(progressTimer_Elapsed); | |
} | |
} | |
[System.ComponentModel.DefaultValue(2000)] | |
public double TimeToReset { | |
get { | |
return timeToReset; | |
} | |
set { | |
if (value > 0) { | |
timeToReset = value; | |
if (!DesignMode) | |
textTimer.Interval = value; | |
} | |
} | |
} | |
public string DefaultResetTo { | |
get { | |
return defaultResetTo; | |
} | |
set { | |
defaultResetTo = value; | |
} | |
} | |
public string ResetTo { | |
get { | |
return resetTo; | |
} | |
set { | |
if (value == null) | |
resetTo = null; | |
else | |
resetTo = value; | |
} | |
} | |
public void SetProgress(int value, int maximum) { | |
SetProgress(value, 0, maximum); | |
} | |
public void SetProgress(int value, int minimum, int maximum) { | |
if (InvokeRequired) { | |
BeginInvoke(new Action<int, int, int>(SetProgress), value, minimum, maximum); | |
return; | |
} | |
this.progress.Maximum = maximum; | |
this.progress.Minimum = minimum; | |
this.progress.Value = value; | |
} | |
public void ShowProgress(int duration) { | |
if (InvokeRequired) { | |
BeginInvoke(new Action<int>(ShowProgress), duration); | |
return; | |
} | |
progress.Visible = true; | |
if (progressTimer.Enabled) | |
progressTimer.Stop(); | |
if (duration > -1) | |
progressTimer.Start(); | |
} | |
public void HideProgress() { | |
if (InvokeRequired) { | |
BeginInvoke(new Action(HideProgress)); | |
return; | |
} | |
progress.Visible = false; | |
} | |
public override void ResetText() { | |
if (InvokeRequired) { | |
BeginInvoke(new Action(ResetText)); | |
} | |
label.Text = defaultResetTo; | |
} | |
Action<string, bool, string> setTextDelegate; | |
public void SetText(string text, bool reset) { | |
SetText(text, reset, defaultResetTo); | |
} | |
public void SetText(string text, bool reset, string resetTo) { | |
if (InvokeRequired) { | |
BeginInvoke(setTextDelegate, text, reset, resetTo); | |
return; | |
} | |
label.Text = text; | |
if (textTimer.Enabled) | |
textTimer.Stop(); | |
if (reset) { | |
textTimer.Start(); | |
} | |
this.resetTo = resetTo; | |
} | |
void textTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { | |
textTimer.Stop(); | |
if (InvokeRequired) | |
BeginInvoke(new Action(() => label.Text = resetTo)); | |
} | |
void progressTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { | |
progressTimer.Stop(); | |
HideProgress(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment