PrograssBar控件
常用属性:Value,Step,Style,MarqueeAnimationSpeed,Maximum,Minimum
方法:PerformStep()Increment()
知识点1:
Style控制PrograssBar的样式,选项为:Block,Continuous,Marquee
当Style=Marquee时,MarqueeAnimationSpeed属性起作用,用于控制动画的速度;
Maximum,Minimum控制PrograssBar的最大值和最小值
Step控制当前值的增量;
知识点2:
使用timer实现一个PrograssBar效果,如下:
using System;
using System.Windows.Forms;
namespace ControlsTest
{
public partial class FormPrograssBar : Form
{
public FormPrograssBar()
{
InitializeComponent();
this.Load += FormPrograssBar_Load;
}
System.Timers.Timer t;
private void FormPrograssBar_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 100;
progressBar1.Minimum = 0;
progressBar1.Value = 0;
progressBar1.Step = 10;
progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Blocks;
t = new System.Timers.Timer();
t.Interval = 500;
t.AutoReset = true;
t.Elapsed += T_Elapsed;
}
private void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (progressBar1.Value < 100)
{
this.Invoke(new Action(() =>
{
//progressBar1.Value += progressBar1.Step;
progressBar1.PerformStep();
label1.Text = (progressBar1.Value * 100 / progressBar1.Maximum).ToString() + "%";
}));
}
else
{
this.Invoke(new Action(() =>
{
label1.Text = "已完成";
}));
t.Stop();
}
}
private void button1_Click(object sender, EventArgs e)
{
t.Start();
}
}
}