zoukankan      html  css  js  c++  java
  • C# 进度条

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    
    namespace ProgressBar
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.progressBar1.Visible = false;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.progressBar1.Visible = true;
                this.llabelProcess.Visible = true;
                // 启动进度条线程
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(NumberIncrement));
                thread.Start();
                Application.DoEvents();
                
    
            }
            
            public void NumberIncrement()
            {
                 EventHandler eh = new EventHandler(DisplayNumber(), pList);//启用一个委托,跳回UI线程.
                 try
                 {
                     this.Invoke(eh, new object[] { null, null });//执行委托
                 }
                 catch (System.Exception ex)
                 {
     
                 }
            }
    
            public void DisplayNumber(object sender, EventArgs e)
            {
                for (int i = 1; i <= 100; i++)
                {
                    SetProcessValue("测试中...", i);
                    Thread.Sleep(50);
                }
            }
    
            //设置进度条显示
            public void SetProcessValue(string TitleName, int value)
            {
                this.progressBar1.Tag = TitleName;
                string str = value.ToString() + "%";
                Font font = new Font("Times New Roman", (float)11, FontStyle.Regular);
                PointF pt = new PointF(this.progressBar1.Width / 2 - 10, this.progressBar1.Height / 2 - 10);
                this.progressBar1.Value = value;
                this.llabelProcess.Text = str;
                this.Refresh();
    
                if (value >= 100)
                {
                    MessageBox.Show("导出完成,请保存!");
                    this.button1.Enabled = true;
                    this.progressBar1.Visible = false;
                    this.llabelProcess.Visible = false;
                }
            }
        }
    }

    更多内容请访问 www.uusystem.com

  • 相关阅读:
    多线程
    Java命令行传参
    IO流
    集合
    Java基础语法
    常见的数据结构
    泛型
    java 集合重要概念 (Set 的存储内存解析)
    java 集合重要概念 (== 和 equals 解读)
    java 集合重要概念 (实现一个简单的斗地主)
  • 原文地址:https://www.cnblogs.com/tianjifa/p/9334182.html
Copyright © 2011-2022 走看看