PrograssBar控件

常用属性:Value,Step,Style,MarqueeAnimationSpeed,Maximum,Minimum

方法:PerformStep()Increment()

 

知识点1:

Style控制PrograssBar的样式,选项为:Block,Continuous,Marquee

当Style=Marquee时,MarqueeAnimationSpeed属性起作用,用于控制动画的速度;

 

Maximum,Minimum控制PrograssBar的最大值和最小值

 

Step控制当前值的增量;

 

知识点2:

使用timer实现一个PrograssBar效果,如下:

 

 

复制代码
using System;
using System.Windows.Forms;

namespace ControlsTest
{
    public partial class FormPrograssBar : Form
    {
        public FormPrograssBar()
        {
            InitializeComponent();
            this.Load += FormPrograssBar_Load;
        }

        System.Timers.Timer t;
        private void FormPrograssBar_Load(object sender, EventArgs e)
        {
            progressBar1.Maximum = 100;
            progressBar1.Minimum = 0;
            progressBar1.Value = 0;
            progressBar1.Step = 10;
            progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Blocks;

            t = new System.Timers.Timer();
            t.Interval = 500;
            t.AutoReset = true;
            t.Elapsed += T_Elapsed;

        }

        private void T_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (progressBar1.Value < 100)
            {
                this.Invoke(new Action(() =>
                {
                    //progressBar1.Value += progressBar1.Step;
                    progressBar1.PerformStep();
                    label1.Text = (progressBar1.Value * 100 / progressBar1.Maximum).ToString() + "%";
                }));
            }
            else
            {
                this.Invoke(new Action(() =>
                {
                    label1.Text = "已完成";
                }));
                t.Stop();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            t.Start();
        }
    }
}
复制代码

 

posted on   hanzq_go  阅读(117)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
· 面试官:你是如何进行SQL调优的?

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示