c#滚动条创建实例,多线程
1.滾動(dòng)條
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 WindowsFormsApplication1
{
? ? public partial class MyProgressBar : Form
? ? {
? ? ? ? public MyProgressBar()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? Initial();
? ? ? ? }
? ? ? ? public static int maxValue = 0;
? ? ? ? public static int minValue = 0;
? ? ? ? public void Initial()
? ? ? ? {
? ? ? ? ? ? this.progressBar1.Maximum = 100;
? ? ? ? ? ? this.progressBar1.Minimum = 0;
? ? ? ? ? ? maxValue = 100;
? ? ? ? ? ? minValue = 0;
? ? ? ? }
? ? ? ? //public delegate void UpdateValue(int value);
? ? ? ? public bool UpdateValue(int nValue)
? ? ? ? {
? ? ? ? ? ? while (!this.IsHandleCreated)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //MessageBox.Show("等待窗體句柄創(chuàng)建");
? ? ? ? ? ? };
? ? ? ? ? ? //try
? ? ? ? ? ? //{
? ? ? ? ? ? ? ? this.Invoke(new Action(() =>
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //if (this.Handle == null) return ;
? ? ? ? ? ? ? ? ? ? if (nValue > 0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? this.label1.Text = nValue.ToString()+"%";
? ? ? ? ? ? ? ? ? ? ? ? if ( nValue < progressBar1.Maximum)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? progressBar1.Value =nValue;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? progressBar1.Value = progressBar1.Maximum;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.Close();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }));
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? //}
? ? ? ? ? ? //catch(Exception ee)
? ? ? ? ? ? //{
? ? ? ? ? ? ? ? //MessageBox.Show(ee.ToString());
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? //}
? ? ? ? }
? ? ? ??
? ? }
}
2.主窗體調(diào)用
?public delegate bool UpdateProgressValue(int value);
? ? ? ? public event UpdateProgressValue UpdateProgressEvent;
? ? ? ? public void CreatedataLineFile(string folderPath)
? ? ? ? {
? ? ? ? ? ? //創(chuàng)建進(jìn)度條
? ? ? ? ? ? Thread th = new Thread(() =>
? ? ? ? ? ? {
? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? MyProgressBar pb = new MyProgressBar();
? ? ? ? ? ? ? ? pb.StartPosition = FormStartPosition.CenterScreen;
? ? ? ? ? ? ? ? UpdateProgressEvent += pb.UpdateValue;
? ? ? ? ? ? ? ? pb.ShowDialog();
? ? ? ? ? ? });
? ? ? ? ? ? th.Start();
? ? ? ? ? ? while (UpdateProgressEvent == null) ;
? ? ? ? ? ? for (int i = 0; i < 1000;i++ )
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Thread.Sleep(10);
? ? ? ? ? ? ? ? UpdateProgressEvent(Convert.ToInt32(i * 1.0 / 1000 * (MyProgressBar.maxValue - MyProgressBar.minValue)+MyProgressBar.minValue));
? ? ? ? ? ? }
? ? ? ? ? ? ? ?
? ? ? ? ? ? return;
}
總結(jié)
以上是生活随笔為你收集整理的c#滚动条创建实例,多线程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: H264学习指南
- 下一篇: jackson 的注解:@JsonPro