-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormProgress.cs
More file actions
84 lines (72 loc) · 2.72 KB
/
FormProgress.cs
File metadata and controls
84 lines (72 loc) · 2.72 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
using System;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TaskProgressExample
{
public partial class FormProgress : Form
{
private Label LabelInfo1;
private Label LabelInfo2;
public ProgressBar ProgressBar;
public Progress<string> Progress;
public CancellationTokenSource CancellationTokenSource;
public FormProgress(string info1, string info2, int progressMax, bool isCancellable)
{
InitializeComponent();
this.Size = new Size(500, 160);
this.StartPosition = FormStartPosition.CenterScreen;
this.ShowInTaskbar = false;
this.Text = "";
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
CancellationTokenSource = new CancellationTokenSource();
var tableLayout = new TableLayoutPanel
{
Dock = DockStyle.Fill,
RowCount = 4,
ColumnCount = 1,
Padding = new Padding(20),
};
Controls.Add(tableLayout);
tableLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 20));
LabelInfo1 = new Label
{
Dock = DockStyle.Fill,
Text = info1,
};
tableLayout.Controls.Add(LabelInfo1);
tableLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 20));
LabelInfo2 = new Label
{
Dock = DockStyle.Fill,
Text = info2,
};
tableLayout.Controls.Add(LabelInfo2);
tableLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 20));
ProgressBar = new ProgressBar
{
Dock = DockStyle.Fill,
Maximum = progressMax > 0 ? progressMax : 100,
Style = progressMax > 0 ? ProgressBarStyle.Blocks : ProgressBarStyle.Marquee,
};
tableLayout.Controls.Add(ProgressBar);
tableLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40));
var ButtonCancel = new Button
{
Anchor = AnchorStyles.None,
Text = isCancellable ? "Cancel" : "Please wait",
Enabled = isCancellable
};
ButtonCancel.Click += (s, e) => { CancellationTokenSource.Cancel(); };
tableLayout.Controls.Add(ButtonCancel);
Progress = new Progress<string>(info =>
{
var segs = info.Split('|');
ProgressBar.Value = int.Parse(segs[0]);
LabelInfo2.Text = segs[0] + ": " + segs[1];
});
}
}
}