zoukankan      html  css  js  c++  java
  • 进度条封装 转

     public class MyProgress
            {
                private int MaxNum;
                Form progressForm = null;
                ProgressBar progressBar1 = null;
                bool Stop = false;
                Label label1;
                public bool ProgressStep(int step)
                {
                    if (Stop)
                    {
    
     
    
                        this.Dispose();
    
     
    
                        return true;
    
     
    
                    }
    
     
    
                    if (progressBar1.Value > progressBar1.Maximum)
                    {
    
     
    
                        this.Dispose();
    
     
    
                        return true;
    
     
    
                    }
    
     
    
                    progressBar1.Value += step;
    
     
    
                    label1.Text = "目前完成:" + (progressBar1.Value * 100 / progressBar1.Maximum) + "%";
    
     
    
                    Application.DoEvents();
                    return false;
                }
    
     
    
                private void btn_Click(object sender, EventArgs e)
                {
    
     
    
                    if (MessageBox.Show("确定终止吗", "终止", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
    
     
    
                        Stop = false;
    
     
    
                    else
    
     
    
                        Stop = true;
    
     
    
                }
    
     
    
                public MyProgress(int Max, String Caption, bool IsCancel)//最大值和标题
                {
                    progressForm = new Form();
                    progressForm.MinimizeBox = false;
                    progressForm.MaximizeBox = false;
                    progressForm.StartPosition = FormStartPosition.CenterScreen;
                    progressForm.Width = 326 + 19;
                    progressForm.Height = 96 + 19 + 20;
                    progressForm.Text = Caption;
                    progressForm.TopMost = true;//设置窗口在上边
                    label1 = new Label();
                    label1.Left = 9; label1.Top = 15;
                    label1.Parent = progressForm;
                    progressBar1 = new ProgressBar();
                    progressBar1.Maximum = Max;
                    MaxNum = Max;
                    progressBar1.Left = 9;
                    progressBar1.Top = 25 + 15;
                    progressBar1.Width = 310;
                    progressBar1.Parent = progressForm;
                    progressBar1.Value = 0;
                    if (IsCancel)
                    {
                        Button btnCancel = new Button();
                        btnCancel.Text = "取消";
                        btnCancel.Left = 240;
                        btnCancel.Top = 54 + 20;
                        btnCancel.Parent = progressForm;
                        btnCancel.Click += new System.EventHandler(this.btn_Click);
                    }
                    progressForm.Show();
                }
    
     
    
                public void Dispose()
                {
                    if (progressForm != null)
                    {
                        progressBar1.Dispose();
                        progressForm.Dispose();
                    }
                }
            }
    
     
    
    
           // 调用测试 进度条窗口
            private void dowork()
            {
                MyProgress myProgress = new MyProgress(100, "进度条", true);
                try
                {
                    for (int i = 0; i < 100; i++)
                    {
                        if (myProgress.ProgressStep(1)) return;
                        Application.DoEvents();//让系统在百忙中抽空刷新
                        Thread.Sleep(100);
                    }
                }
                finally
                {
                    myProgress.Dispose();
                }
            }
    
     
    
       
    
     
    
             private void button2_Click(object sender, EventArgs e)
            {
                this.dowork();
            }
    
     
  • 相关阅读:
    今天整理一下以前各博客网站上的文章
    转一篇详解Excel逻辑函数的文章
    Google中国的首页变化
    [转]在QuantumGrid4.5中手动添加数据
    [转]VISTA服务介绍
    Idiomatic Phrases Game zoj 2750 Dijkstra
    Fleury 求欧拉回路
    QS Network ZOJ 1586 Prim
    Burn the Linked Camp ZOJ 2770 差分约束系统 SPFA
    ZOJ 1092 POJ 2240 Arbitrage Floyd
  • 原文地址:https://www.cnblogs.com/bantongshui/p/3170016.html
Copyright © 2011-2022 走看看