-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProgressDialog.cs
More file actions
89 lines (75 loc) · 2.75 KB
/
Copy pathProgressDialog.cs
File metadata and controls
89 lines (75 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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 AndroidController
{
public partial class ProgressDialog : Form
{
public ProgressDialog()
{
InitializeComponent();
}
private void ProgressDialog_Load(object sender, EventArgs e)
{
new FormTranslator(this);
backgroundWorker1.RunWorkerAsync();
}
public bool Run(Control parent) {
if (parent != null)
{
this.StartPosition = FormStartPosition.Manual;
this.Top = parent.Top + parent.Height / 2 - this.Height / 2;
this.Left = parent.Left + parent.Width / 2 - this.Width / 2;
}
return ShowDialog(parent)==DialogResult.OK;
}
public void RunAsync(Control parent) {
if (parent != null)
{
this.StartPosition = FormStartPosition.Manual;
this.Top = parent.Top + parent.Height / 2 - this.Height / 2;
this.Left = parent.Left + parent.Width / 2 - this.Width / 2;
}
Show(parent);
}
Action<BackgroundWorker> action;
public static ProgressDialog Schedule(Action<BackgroundWorker> action) {
return new ProgressDialog() { action = action };
}
private void ProgressDialog_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = backgroundWorker1.IsBusy;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(50);
action.Invoke(backgroundWorker1);
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Style = e.ProgressPercentage==0 ? ProgressBarStyle.Marquee : ProgressBarStyle.Continuous;
if (e.ProgressPercentage != 0) {
progressBar1.Value = e.ProgressPercentage;
}
if (e.UserState != null) {
lblProgress.Text = e.UserState.ToString();
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
DialogResult = button1.Enabled ? DialogResult.OK : DialogResult.Cancel;
Close();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
backgroundWorker1.CancelAsync();
}
}
}