zoukankan      html  css  js  c++  java
  • 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;
            }
        }
    }
  • 相关阅读:
    oracle-PL/SQL1
    ROS之Gazebo
    ROS之urdf 2
    ROS之urdf 1
    ROS 面部识别
    ROS x Arduino
    STM32F0的低功耗模式
    项目进度
    C++函数返回为引用
    STM32F0的多路ADC 无DMA
  • 原文地址:https://www.cnblogs.com/greatverve/p/1523781.html
Copyright © 2011-2022 走看看