欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#?Winform實現(xiàn)進度條顯示

 更新時間:2022年07月27日 14:36:13   作者:BoomBiuBiu  
這篇文章主要為大家詳細介紹了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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論