基本信息
源码名称:3分钟掌握C#的ProgressBar控件
源码大小:0.19M
文件格式:.zip
开发语言:C#
更新时间:2020-05-31
   源码介绍

这个实例(https://www.daboke.com)可以让你3分钟掌握C#的ProgressBar控件,走过路过不要错过!

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;

namespace progressBar
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                return;
            }
            else
            {
                progressBar1.Value = 0;
                progressBar1.Minimum = 0;
                progressBar1.Maximum = int.Parse(textBox1.Text);
                output("进度条开始");
                timer1.Enabled = true;
            }
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            if (timer1.Enabled == true)
            {
                output("进度条暂停");
                button2.Text = "继续";
                timer1.Enabled = false;
            }
            else
            {
                output("进度条继续");
                button2.Text = "暂停";
                timer1.Enabled = true;

            }
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            output("进度条停止");
            progressBar1.Value = 0;
        }

        private void output(string info)
        {
            textBox2.Text = "";
            textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss")   info   "\r\n");//打印时间和文本信息
        }

        private void Timer1_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value < progressBar1.Maximum)
            {
                progressBar1.Value  ;//进度值自增
                output("进度运行中("   progressBar1.Value.ToString()   "/"   progressBar1.Maximum   ")...");
            }
            else
            {
                output("进度完成");
                timer1.Enabled = false;
            }
        }

        private void Button4_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://www.daboke.com");//欢迎访问大博客,探索更多编程实战案例!
        }

        private void Button5_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://www.daboke.com/program/progressbar.html");//原文链接!
        }

        private void Button6_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://space.bilibili.com/580719958");//Bilibili-编程实战视频,Up主:编程自修室!
        }
    }
}