C# Winform实现进度条显示

作者:BoomBiuBiu 时间:2023-09-14 15:47:51 

本文实例为大家分享了C# Winform实现进度条显示的具体代码,供大家参考,具体内容如下

创建一个窗体,命名为StartForm

C# Winform实现进度条显示

添加一个timer控件并更改名字为timerStart

C# Winform实现进度条显示

 添加一个ProgressBar控件,并调整一下属性:

C# Winform实现进度条显示

 StartForm窗体的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace MVtest
{
    public partial class StartForm : Form
    {
        public StartForm()
        {
            InitializeComponent();
        }
 
 
        //修饰符  delegate  返回值类型  委托名 ( 参数列表 );
        private delegate void TIMEinvoke(int val);
 
        //委托显示客户端列表
        private void DataDisplay(int val)
        {
            if(this.InvokeRequired)
            {
                TIMEinvoke myIvoke = new TIMEinvoke(DataDisplay);
                this.Invoke(myIvoke,new object[] { val });
            }
            else
            {
                this.PBress.Value = val;
            }
        }

        //事件
        int times = 0;
        private void timerStart_Tick(object sender, EventArgs e)
        {
            times++;
            DataDisplay(times);
            if(times>=20)
            {
                PBress.Visible=false;
                //关闭timer控件
                timerStart.Enabled=false;
                this.Close();
            }
        }
        
        //窗体加载
        private void StartForm_Load(object sender, EventArgs e)
        {
            timerStart.Interval = 100;
            timerStart.Enabled=true;
            PBress.Visible=true;
            PBress.Maximum = 32;
        }
    }
}

在Program.cs里面加入代码:

namespace MVtest
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new StartForm());
            Application.Run(new MainForm());
        }
    }
}

C# Winform实现进度条显示

来源:https://blog.csdn.net/BoomBiuBiu/article/details/124489677

标签:C#,Winform,进度条
0
投稿

猜你喜欢

  • Android编程之在SD卡上进行文件读写操作实例详解

    2022-04-15 10:29:50
  • 分享C#操作内存读写方法的主要实现代码

    2022-10-08 08:08:44
  • C#中委托用法实例详解

    2022-11-02 23:24:40
  • 浅析JDK12的五大重要新特性(推荐)

    2023-01-28 19:09:24
  • Java中的强引用,软引用,弱引用,虚引用的作用介绍

    2023-08-27 11:03:28
  • c#基于WinForm的Socket实现简单的聊天室 IM

    2021-11-27 04:47:57
  • Java中实现获取路径的方法汇总

    2022-12-19 08:10:54
  • 详谈java中int和Integer的区别及自动装箱和自动拆箱

    2023-01-18 23:25:20
  • Android RadarView雷达图(蜘蛛网图)的实现代码

    2022-12-09 21:45:19
  • Android中通知Notification使用实例(振动、灯光、声音)

    2021-09-28 20:00:01
  • Java多线程-线程的同步与锁的问题

    2023-11-29 01:40:12
  • 结合线程池实现apache kafka消费者组的误区及解决方法

    2023-08-06 15:40:31
  • Java几种常用的断言风格你怎么选

    2021-10-30 23:30:32
  • 详解使用Spring的BeanPostProcessor优雅的实现工厂模式

    2023-01-14 02:15:53
  • 解析JavaSe的内部类

    2022-08-14 18:19:33
  • Java多种经典排序算法(含动态图)

    2023-09-24 00:45:02
  • Java使用BIO和NIO进行文件操作对比代码示例

    2023-04-18 16:14:21
  • 关于Java中增强for循环使用的注意事项

    2021-08-09 16:47:43
  • Android studio实现简单计算器的编写

    2022-08-21 05:58:55
  • spring cloud 之 客户端负载均衡Ribbon深入理解

    2023-02-15 15:00:58
  • asp之家 软件编程 m.aspxhome.com