PageRenderTime 138ms CodeModel.GetById 134ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/WorldView/FormProgressDialog.cs

#
C# | 90 lines | 68 code | 18 blank | 4 comment | 4 complexity | 629bf06c9059c665a3da970af1623bf2 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Linq;
 7using System.Text;
 8using System.Windows.Forms;
 9
10namespace MoreTerra
11{
12	public partial class FormProgressDialog : Form
13	{
14		private Boolean cancel;
15		private String name;
16		private BackgroundWorker bw;
17		private Boolean success;
18
19		public FormProgressDialog(String titleName, Boolean allowsCancel, BackgroundWorker worker)
20		{
21			bw = worker;
22			cancel = allowsCancel;
23			name = titleName;
24
25			this.ShowInTaskbar = false;
26			InitializeComponent();
27
28			this.Icon = Properties.Resources.Cannon;
29		}
30
31		private void FormProgressDialog_Load(object sender, EventArgs e)
32		{
33			Point pt;
34			Size size;
35			Text = name;
36
37			buttonCancel.Enabled = cancel;
38			textBoxOutput.Text = "";
39
40			// Set the box to the center of the window.
41			pt = this.Owner.Location;
42			size = this.Owner.Size;
43
44			pt.X = pt.X + (size.Width / 2) - (this.Size.Width / 2);
45			pt.Y = pt.Y + (size.Height / 2) - (this.Size.Height / 2);
46
47			this.Location = pt;
48		}
49
50		private void buttonCancel_Click(object sender, EventArgs e)
51		{
52			// ?
53			// Somehow I need to pass back that we need to cancel.
54			// Although we could handle it ourselves.
55		}
56
57
58		public void worker_Completed(object sender, RunWorkerCompletedEventArgs e)
59		{
60
61			if (e.Cancelled)
62				success = false;
63
64			success = true;
65
66			this.Close();
67		}
68
69		public void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
70		{
71			if (e.ProgressPercentage > progressBarTotal.Value)
72				progressBarTotal.Value = e.ProgressPercentage;
73
74			if (e.UserState != null)
75			{
76				textBoxOutput.Text += ((String)e.UserState + Environment.NewLine);
77				textBoxOutput.Select(textBoxOutput.TextLength, 0);
78				textBoxOutput.ScrollToCaret();
79			}
80		}
81
82		public Boolean Success
83		{
84			get
85			{
86				return success;
87			}
88		}
89	}
90}