C#?Winform實(shí)現(xiàn)進(jìn)度條顯示
本文實(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());
? ? ? ? }
? ? }
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
WPF利用RPC調(diào)用其他進(jìn)程的方法詳解
這篇文章主要給大家介紹了關(guān)于WPF利用RPC調(diào)用其他進(jìn)程的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-05-05
C#利用接口實(shí)現(xiàn)多語(yǔ)種選擇功能
這篇文章主要為大家詳細(xì)介紹了如何C#利用接口實(shí)現(xiàn)多語(yǔ)種選擇功能,即多語(yǔ)言切換的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2024-02-02
C#實(shí)現(xiàn)斐波那契數(shù)列的幾種方法整理
這篇文章主要介紹了C#實(shí)現(xiàn)斐波那契數(shù)列的幾種方法整理,主要介紹了遞歸,循環(huán),公式和矩陣法等,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09

