zoukankan      html  css  js  c++  java
  • wpf使用进度条,趣味学习

    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 进度条Again
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
            }
            private bool isok=true;
            private void button1_Click(object sender, EventArgs e)//开始按钮
            {   
                if(string.IsNullOrWhiteSpace(textBox1.Text))
                {
                    return;
                }
                else
                {
                    button2.Enabled = true;
                    button3.Enabled = true;
                    toolStripProgressBar1.Value = 0;//进度条当前值为0
                    toolStripProgressBar1.Minimum = 0;//进度条最小值为0
                    toolStripProgressBar1.Maximum = Convert.ToInt32(textBox1.Text);//进度条最大值为文本框1输入的数
                    timer1.Enabled = true;
                }
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)//当文本框1文本改变的时候button1才可以用
            {
                button1.Enabled = true;
            }
    
            private void button2_Click(object sender, EventArgs e)//暂停
            {
                if (button2.Text == "暂停")
                {
                    timer1.Enabled = false;
                    button2.Text = "继续";
                    textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss") + "进度暂停" + "
    ");
                }
                else
                {
                    timer1.Enabled = true;
                    button2.Text = "暂停";
                    textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss") + "进度继续" + "
    ");
                }
                
            }
    
            private void button3_Click(object sender, EventArgs e)//停止
            {
                timer1.Enabled = false;
                toolStripProgressBar1.Value = 0;
                textBox2.Text = "";
                textBox1.Text = "";
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
    
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (toolStripProgressBar1.Value < toolStripProgressBar1.Maximum)//如果进度条当前的值小于进度条最大的值
                {
                    toolStripProgressBar1.Value++;//就把进度条的当前值++
                    textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss") + "当前进度为[" + toolStripProgressBar1.Value + "/" + toolStripProgressBar1.Maximum + "]...." + "
    ");//拼接字符串
    
                }
                else
                {
                    textBox2.Text = "";
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
        }
    }
  • 相关阅读:
    周五,远程连接及总体流程
    C++ 图片浏览
    深度解析Java内存的原型
    找不到class
    js读写cookie
    不利用临时变量,交换两个变量的值
    插入排序
    算法:一个排序(第一个最大,第二个最小,第三个其次大,第四其次小...)
    c#缓存介绍(1)
    JavaScript中创建自定义对象
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4621206.html
Copyright © 2011-2022 走看看