網站首頁 編程語言 正文
本文實例為大家分享了C# Winform實現進度條顯示的具體代碼,供大家參考,具體內容如下
創建一個窗體,命名為StartForm
添加一個timer控件并更改名字為timerStart
?添加一個ProgressBar控件,并調整一下屬性:
?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());
? ? ? ? }
? ? }
}
原文鏈接:https://blog.csdn.net/BoomBiuBiu/article/details/124489677
相關推薦
- 2022-06-01 Python?分形算法代碼詳解_python
- 2022-09-10 Go語言中使用urfave/cli命令行框架_Golang
- 2024-01-13 nvm命令
- 2022-03-30 android?RecyclerView添加footerview詳解_Android
- 2022-09-01 Python?類方法和靜態方法之間的區別_python
- 2022-06-22 深入淺析C/C++?的條件編譯_C 語言
- 2022-11-11 Python深度學習之FastText實現文本分類詳解_python
- 2022-09-16 Python中的socket網絡模塊介紹_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支