什么是progressBar
ProgressBar类主耍用来显示进度,其Maximum和Minimum属性分别表示进度条的最大和最小值;Value属性则表示进度条当前的值,该值必须在Maximum和Minimum属性设置的范围内;Step属性表示进度条的步进速度。
Timer类是一个定时器,可以控制定时触发某些事件,可以使用Enabled属性来控制是否激活定时器,使用Tick事件来实现定时器触发后实现的功能。
来看今天的例子。
1、创建进度条窗口
2、在其他窗口中调用方法ShowProcess(int percent,string message)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Mes.Core; namespace HCMDoImport { public partial class ProcessBarForm : BaseForm { int processPercent = 0; string message = ""; public string Message { get { return message; } set { message = value; this.label1.Text = message; } } public int ProcessPercent { get { return processPercent; } set { processPercent = value; if (processPercent >= 100) this.Close(); this.progressBar1.Value = processPercent; } } public ProcessBarForm() { InitializeComponent(); } /// <summary> /// 更新进度 /// </summary> /// <param name="percent">进度,小于等于100</param> /// <param name="message">消息</param> public void ShowProcess(int percent,string message) { this.Show(); this.ProcessPercent = percent; this.Message = message; this.progressBar1.Refresh(); this.label1.Refresh(); } private void ProcessBarForm_Load(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; } private void ProcessBarForm_FormClosing(object sender, FormClosingEventArgs e) { this.Cursor = Cursors.Default; } } }