// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Drawing; using System.Windows.Forms; using System.Threading; public class MainForm : Form { private ProgressBar bar; private Button start; private Button abort; private Thread t; public MainForm() { bar = new ProgressBar(); start = new Button(); abort = new Button(); SuspendLayout(); bar.Location = new Point(50, 50); bar.Size = new Size(200, 50); bar.Name = "Progress Bar"; bar.Minimum = 0; bar.Maximum = 60; bar.Value = 0; bar.Step = 1; start.Location = new Point(50,150); start.Size = new Size(200, 50); start.Name = "Start Button"; start.Text = "Start"; start.Click += new EventHandler(StartClick); abort.Location = new Point(50,250); abort.Size = new Size(200, 50); abort.Name = "Abort Button"; abort.Text = "Abort"; abort.Click += new EventHandler(AbortClick); ClientSize = new Size(300, 350); Controls.Add(bar); Controls.Add(start); Controls.Add(abort); Name = "Main Form"; Text = "Main Form"; ResumeLayout(false); } void Copy() { for(int i = 0; i < 60; i++) { bar.Value = i; Thread.Sleep(1000); } } void StartClick(object sender, EventArgs e) { t = new Thread(new ThreadStart(Copy)); t.Start(); } void AbortClick(object sender, EventArgs e) { t.Abort(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); Application.Exit(); Environment.Exit(0); } }