網(wǎng)站首頁 編程語言 正文
本文實(shí)例為大家分享了C# Winform實(shí)現(xiàn)進(jìn)度條顯示的具體代碼,供大家參考,具體內(nèi)容如下
創(chuàng)建一個(gè)窗體,命名為StartForm
添加一個(gè)timer控件并更改名字為timerStart
?添加一個(gè)ProgressBar控件,并調(diào)整一下屬性:
?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 ?返回值類型 ?委托名 ( 參數(shù)列表 );
? ? ? ? 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;
? ? ? ? ? ? ? ? //關(guān)閉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>
? ? ? ? /// 應(yīng)用程序的主入口點(diǎn)。
? ? ? ? /// </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
相關(guān)推薦
- 2022-06-02 C語言實(shí)現(xiàn)簡單的抽獎(jiǎng)系統(tǒng)_C 語言
- 2022-12-24 Kubernetes?kubectl中Pod創(chuàng)建流程源碼解析_云和虛擬化
- 2024-01-27 Rosetta error:bad input問題(解決)
- 2022-06-29 徹底掌握C語言strcat函數(shù)的用法_C 語言
- 2022-11-05 Nginx配置文件中l(wèi)ocation配置的多種場(chǎng)景_nginx
- 2022-04-01 git clone 失敗
- 2022-12-29 Kotlin?Service服務(wù)組件開發(fā)詳解_Android
- 2022-04-01 本地存儲(chǔ)(Local Storage) 和 會(huì)話存儲(chǔ)(Session Storage)
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支