进度条代码
代码来
C# code
#region MarqueeProcess 显示连续滚动的进度条
///
/// 显示连续滚动的进度条
///
public void MarqueeProcess()
{
this.Hide();
m_ProgressThread = new Thread(new ThreadStart(Progr
essAutoRun));
m_ProgressThread.IsBackground = true;
m_ProgressThread.Start();
}
private void ProgressAutoRun()
{
frmProgress fp = new frmProgress();
fp.StepValue = 1;
fp.NewProcess(100);
while (true)
{
if (fp.CurProgressValue >= fp.MaxProgressValue)
fp.SetProcessValue(fp.MinProgressValue);
else
fp.SetProcessValue(fp.CurProgressValue + f
p.StepValue);
fp.Refresh();
Thread.Sleep(100);
}
}
#endregion
C# code
private Thread m_ProgressThread;
#region StepValue 阶段进度值
///
/// 阶段进度值
///
public int StepValue
{
get
{
return this.progressBar1.Step;
}
set
{
this.progressBar1.Step = value;
}
}
#endregion
#region CurProgressValue 当前进度值
///
/// 当前进度值
///
public int CurProgressValue
{
get
{
return this.progressBar1.Value;
}
}
#endregion
#region MinProgressValue 最低进度值
///
/// 最低进度值
///
public int MinProgressValue
{
get
{
return this.progressBar1.Minimum;
}
set
{
this.progressBar1.Minimum = value;
}
}
#endregion
#region MaxProgressValue 最高进度值
///
/// 最高进度值
///
public int MaxProgressValue
{
get
{
return this.progressBar1.Maximum;
}
}
#endregion
#region NewProcess 创建并显示进度条
///
/// 创建并显示进度条
///
///
public void NewProcess(int ProgressMaximum)
{
this.progressBar1.Style = ProgressBarStyle.Blocks;
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = ProgressMaximum;
this.progressBar1.Value = 0;
this.TopMost = true;
this.Visible = true;
}
#endregion
#region HideProcess 隐藏进度条
///
/// 隐藏进度条
///
public void HideProcess()
{
if (m_ProgressThread != null)
{
m_ProgressThread.Abort();
m_ProgressThread = null;
}
if (this.Visible)
{
this.Visible = false;
}
}
#endregion
#region SetProcessValue 设置进度值
///
/// 设置进度值
///
///
进度值
public void SetProcessValue(int value)
{
if (value < this.progressBar1.Minimum)
value = this.progressBar1.Minimum;
if (value > this.progressBar1.Maximum)
value = this.progressBar1.Maximum;
this.progressBar1.Value = value;
this.Refresh();
}
#endregion
C# code
frmProgress pmTest = new frmProgress();
pmTest.MarqueeProcess();
// 执行很慢的操作代码中间放
pmTest.HideProcess();