• 进度条


    一、主要实现的是输入进度条最大数,点开始进度条会往前加载,同时将日志存到文本框2里面去

    二、编辑代码

    namespace 进度条Again
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = false;
            }
          
            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)//暂停
            {   
           button1.Enabled = false;
    if (button2.Text == "暂停") { timer1.Enabled = false; button2.Text = "继续"; textBox2.AppendText(DateTime.Now.ToString("HH:mm:ss") + "进度暂停" + " ");//AppendText追加文本 } 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(); } } }

  • 相关阅读:
    第四章例4-5
    第四章例4-4
    修改oracle 客户端PL/SQL 的路径问题
    解决div float后,父div高度无法自适应的问题
    include与jsp:include与s:action与s:include与iframe用法汇总
    解决js中onMouseOut事件冒泡的问题
    strut2配置action class 问题
    html块级元素与行内元素
    Tomcat 启动不了的问题
    oracle远程导入导出
  • 原文地址:https://www.cnblogs.com/lk-kk/p/4617151.html
Copyright © 2020-2023  润新知