C#?Winform實現(xiàn)進度條顯示
本文實例為大家分享了C# Winform實現(xiàn)進度條顯示的具體代碼,供大家參考,具體內(nèi)容如下
創(chuàng)建一個窗體,命名為StartForm
添加一個timer控件并更改名字為timerStart
添加一個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; ? ? ? ? ? ? ? ? //關閉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()); ? ? ? ? } ? ? } }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C#百萬數(shù)據(jù)查詢出現(xiàn)超時問題的解決方法
這篇文章主要介紹了C#百萬數(shù)據(jù)查詢出現(xiàn)超時問題的解決方法,是非常實用的技巧,需要的朋友可以參考下2014-09-09.NET實現(xiàn)定時發(fā)送郵件代碼(兩種方式)
經(jīng)常發(fā)郵件的朋友都知道,郵箱有個特殊功能,可以設定郵件發(fā)送時間,定時發(fā)送,這個功能是怎么實現(xiàn)的呢?接下來,小編給大家分享.NET實現(xiàn)定時發(fā)送郵件的代碼,有需要的朋友可以參考下2015-08-08C#(int)中Convert、Parse、TryParse的區(qū)別
Convert.ToInt32、int.Parse(Int32.Parse)、int.TryParse、(int) 四者都可以解釋為將類型轉(zhuǎn)換為 int,那它們的區(qū)別是什么呢?2013-04-04在WCF數(shù)據(jù)訪問中使用緩存提高Winform字段中文顯示速度的方法
這篇文章主要介紹了在WCF數(shù)據(jù)訪問中使用緩存提高Winform字段中文顯示速度的方法,是非常實用的功能,需要的朋友可以參考下2014-09-09C# TabControl手動觸發(fā)DrawItem的實現(xiàn)
本文主要介紹了C# TabControl手動觸發(fā)DrawItem的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-02-02C#使用表達式樹(LambdaExpression)動態(tài)更新類的屬性值(示例代碼)
這篇文章主要介紹了C#使用表達式樹(LambdaExpression)動態(tài)更新類的屬性值,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-01-01C#?DateTime.Now.ToString()?用法示例講解
這篇文章主要介紹了C#?DateTime.Now.ToString()?用法,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧2024-01-01C#使用LINQ中Enumerable類方法的延遲與立即執(zhí)行的控制
這篇文章主要介紹了C#的LINQ查詢中Enumerable類方法的延遲與立即執(zhí)行,LINQ語言集成查詢可以讓C#和VB以查詢數(shù)據(jù)庫相同的方式操作內(nèi)存數(shù)據(jù),需要的朋友可以參考下2016-03-03