• C# WinForm控件TrackBar与ProgressBar及Timer的用法


    源码下载:http://www.0379zd.com/news/show/26100.htm

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

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

            
    private void button1_Click(object sender, EventArgs e)
            {
                
    if (timer1.Enabled == true)
                {
                    timer1.Enabled 
    = false;
                    button1.Text 
    = "开始";
                }
                
    else
                {
                    timer1.Enabled 
    = true;
                    button1.Text 
    = "停止";
                }
            }

            
    private void trackBar1_Scroll(object sender, EventArgs e)
            {
                
    //使用trackBar1调整步进速度,不能为零
                timer1.Interval = Convert.ToInt16(5000 / trackBar1.Value);
            }

            
    private void timer1_Tick(object sender, EventArgs e)
            {
                
    if (this.progressBar1.Value == this.progressBar1.Maximum)
                {
                    
    this.progressBar1.Value = this.progressBar1.Minimum;
                }
                
    else
                {
                    
    //主要是这个函数,步进
                    this.progressBar1.PerformStep();
                }
                
    //计算百分比
                int intPercent;
                intPercent 
    = 100 * (this.progressBar1.Value - this.progressBar1.Minimum) / (this.progressBar1.Maximum - this.progressBar1.Minimum);
                label1.Text 
    = Convert.ToInt16(intPercent).ToString() + "%";
            }

            
    private void Form1_Load(object sender, EventArgs e)
            {
                
    this.progressBar1.Maximum = 1000;
                
    this.progressBar1.Step = 10;
            }
        }
    }
  • 相关阅读:
    关于maven的一些记录
    3des和tomcat部署
    java串口通讯
    mina自定义编解码
    Linux 下关闭防火墙设置
    查看本机IP
    linux修改localhost方法
    centos 6.5下使用中文输入法
    linux:can't save files
    ng-model取不到值的问题
  • 原文地址:https://www.cnblogs.com/greatverve/p/1523781.html
Copyright © 2020-2023  润新知