winform執行時可以拖動視窗(C#多執行緒)
阿新 • • 發佈:2018-12-15
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; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private delegate void SetProgessBar(int value); private void setProgessBar(int value) { if (this.InvokeRequired) { SetProgessBar spb = new SetProgessBar(setProgessBar); this.Invoke(spb, new object[] { value }); } else { this.progressBar1.Value = value; } } private void SetPro() { MessageBox.Show(progressBar1.Maximum.ToString()); MessageBox.Show(progressBar1.Minimum.ToString()); for (int i = 0; i <= 100; i++) { Thread.Sleep(200); //progressBar1.Value = i; setProgessBar(i); } } private void button1_Click(object sender, EventArgs e) { Thread th = new Thread(new ThreadStart(SetPro)); th.Start(); } } }