首页 > 代码库 > C# 模式窗口下更新进度条
C# 模式窗口下更新进度条
public partial class frmProcessBar : Form { public frmProcessBar() { InitializeComponent(); } public bool Increase(int nValue) { if (nValue > 0) { if (progressBar1.Value + nValue < progressBar1.Maximum) { progressBar1.Value += nValue; return true; } else { progressBar1.Value = progressBar1.Maximum; this.Close(); return false; } } return false; } }
private frmProcessBar myProcessBar = null; private delegate bool IncreaseHandle(int nValue); private IncreaseHandle myIncrease = null;private void btnRun_Click(object sender, EventArgs e) { Thread thdSub = new Thread(new ThreadStart(ThreadFun)); thdSub.Start(); } private void ShowProcessBar() { myProcessBar = new frmProcessBar(); // Init increase event myIncrease = new IncreaseHandle(myProcessBar.Increase); myProcessBar.ShowDialog(); } private void ThreadFun() { MethodInvoker mi = new MethodInvoker(ShowProcessBar); this.BeginInvoke(mi); bool blnIncreased = false; object objReturn = null; do { Thread.Sleep(50); objReturn = this.Invoke(this.myIncrease,new object[] { 1 }); blnIncreased = (bool)objReturn; } while (blnIncreased); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。