日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C#?Winform實現進度條顯示_C#教程

作者:BoomBiuBiu ? 更新時間: 2022-09-20 編程語言

本文實例為大家分享了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

欄目分類
最近更新