1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/// <summary>
/// Class that handle an effect when something need to wait.
///
/// http://en.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Creating_a_Custom_ToolStripItem
/// </summary>
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip |
ToolStripItemDesignerAvailability.StatusStrip)]
public partial class StatusBarWaiting : ToolStripControlHost
{
/// <summary>
/// Delegate method used for the cross thread operation
/// </summary>
private delegate void delCrossThreadMethod();
private FlowLayoutPanel controlPanel;
private Label lblNumberRows = new Label();
private Label lblTimes = new Label();
private ProgressBar pgbProgress = new ProgressBar();
/// <summary>
/// Thread that show progress. Especially the progress of the
/// threadPersistence above. This thread have stop condition
/// related to the state of life of threadPersistence.
/// </summary>
private Thread threadProgressBar;
/// <summary>
/// Record the time for loading the action list.
/// </summary>
private TimeKeeper timeKeeperActionList;
/// <summary>
/// Waiting progress bar
/// </summary>
private bool waitingPersistence;
private string textNumberResult = String.Empty;
public StatusBarWaiting():base(new FlowLayoutPanel())
{
InitializeComponent();
this.timeKeeperActionList = new TimeKeeper();
// Set up the FlowLayouPanel.
controlPanel = (FlowLayoutPanel)base.Control;
controlPanel.BackColor =System.Drawing.Color.Transparent;
this.ResultNumber = 0;
lblTimes.Text = "0 seconds";
pgbProgress.Style = ProgressBarStyle.Continuous;
pgbProgress.Maximum = 50;
pgbProgress.Visible = false;
pgbProgress.Size = new System.Drawing.Size(150, 12);
controlPanel.Controls.Add(lblNumberRows);
controlPanel.Controls.Add(lblTimes);
controlPanel.Controls.Add(pgbProgress);
}
public void start()
{
if (this.Control.InvokeRequired)
{
this.Control.BeginInvoke(new delCrossThreadMethod(start));
return;
}
this.pgbProgress.Value = 0;
this.pgbProgress.Visible = true;
threadProgressBar = new Thread(new ThreadStart(threadMoveProgressBar));
threadProgressBar.Name = "Progress";
threadProgressBar.Start();
this.timeKeeperActionList.start();
//this.controlPanel.ResumeLayout(true);
//this.pgbProgress.ResumeLayout(true);
//this.controlPanel.Update();
//this.controlPanel.Refresh();
//this.pgbProgress.Refresh();
//this.pgbProgress.Update();
}
public void stop()
{
if (this.Control != null)
{
if (this.Control.InvokeRequired)
{
this.Control.BeginInvoke(new delCrossThreadMethod(stop));
return;
}
try
{
this.timeKeeperActionList.stop();
this.pgbProgress.Value = 0;
this.pgbProgress.Visible = false;
if (threadProgressBar != null)
{
threadProgressBar.Abort();
threadProgressBar = null;
waitingPersistence = false;
}
}
catch (Exception e)
{
Log.getInstance().add(new Feedback(Log.LOG_ERROR, "StatusBarWaiting internal error : " + e.Message));
}
}
}
/// <summary>
/// Loop that invoke to the good thread the move of the
/// progress bar
/// </summary>
private void threadMoveProgressBar()
{
waitingPersistence = true;
while (waitingPersistence)
{
Thread.Sleep(200);
moveProgressBar();
}
}
/// <summary>
/// Move the progress bar of 1 unit
/// </summary>
private void moveProgressBar()
{
if (this.Control != null)
{
if (this.Control.InvokeRequired)
{
this.Control.BeginInvoke(new delCrossThreadMethod(moveProgressBar));
return;
}
this.pgbProgress.Value = pgbProgress.Value % pgbProgress.Maximum + 1;
this.Control.Refresh();
this.pgbProgress.Refresh();
}
}
public int ResultNumber
{
set
{
if (value>1)
this.textNumberResult = (value + " results");
else
this.textNumberResult = (value + " result");
updateNumberRow();
}
}
private void updateNumberRow()
{
if (this.Control != null)
{
if (this.Control.InvokeRequired)
{
this.Control.BeginInvoke(new delCrossThreadMethod(updateNumberRow));
return;
}
this.lblNumberRows.Text = this.textNumberResult;
}
}
} |
Partager