This repository has been archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.cs
294 lines (249 loc) · 10.8 KB
/
Program.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
using System;
using System.Windows.Forms;
using KPreisser.UI;
namespace TaskDialogExample
{
class Program
{
[STAThread]
static void Main()
{
ShowTaskDialogExample();
Console.ReadKey();
}
private static void ShowTaskDialogExample()
{
var dialogPage = new TaskDialogPage()
{
Title = "Example 1",
Instruction = "Hello Task Dialog! 👍",
Text = "Hi, this is <A HREF=\"link1\">the Content</A>.\nBlah blah blah…",
Icon = TaskDialogStandardIcon.SecuritySuccessGreenBar,
Footer =
{
Text = "This is the <A HREF=\"link2\">footer</A>.",
Icon = TaskDialogStandardIcon.Warning,
},
Expander =
{
Text = "Expanded Information!",
ExpandFooterArea = true
},
ProgressBar = new TaskDialogProgressBar(),
CustomButtonStyle = TaskDialogCustomButtonStyle.CommandLinks,
EnableHyperlinks = true,
AllowCancel = true,
CanBeMinimized = true,
SizeToContent = true,
};
dialogPage.Created += (s, e) =>
{
Console.WriteLine("Main Contents created!");
};
dialogPage.Destroyed += (s, e) =>
{
Console.WriteLine("Main Contents destroyed!");
};
dialogPage.Expander.ExpandedChanged += (s, e) =>
{
Console.WriteLine("Expander Expanded Changed: " + dialogPage.Expander.Expanded);
};
var dialog = new TaskDialog(dialogPage);
dialog.Opened += (s, e) =>
{
Console.WriteLine("Dialog opened!");
};
dialog.Shown += (s, e) =>
{
Console.WriteLine("Dialog shown!");
};
dialog.Closing += (s, e) =>
{
Console.WriteLine("Dialog closing!");
};
dialog.Closed += (s, e) =>
{
Console.WriteLine("Dialog closed!");
};
//dialog.Activated += (s, e) =>
//{
// Console.WriteLine("Dialog activated!");
//};
//dialog.Deactivated += (s, e) =>
//{
// Console.WriteLine("Dialog deactivated!");
//};
dialogPage.ProgressBar.Value = 1;
TaskDialogStandardButton buttonYes = dialogPage.StandardButtons.Add(TaskDialogResult.Yes);
buttonYes.Enabled = false;
TaskDialogStandardButton buttonNo = dialogPage.StandardButtons.Add(TaskDialogResult.No);
// Add a hidden "Cancel" button so that we can get notified when the user
// closes the dialog through the window's X button or with ESC (and could
// cancel the close operation).
TaskDialogStandardButton buttonCancelHidden = dialogPage.StandardButtons.Add(TaskDialogResult.Cancel);
buttonCancelHidden.Visible = false;
buttonCancelHidden.Click += (s, e) =>
{
Console.WriteLine("Cancel clicked!");
};
long timerCount = 2;
var dialogPageTimer = null as Timer;
dialogPage.Created += (s, e) =>
{
dialogPageTimer = new Timer()
{
Enabled = true,
Interval = 200
};
dialogPageTimer.Tick += (s2, e2) =>
{
// Update the progress bar if value <= 35.
if (timerCount <= 35)
{
dialogPage.ProgressBar.Value = (int)timerCount;
}
else if (timerCount == 36)
{
dialogPage.ProgressBar.State = TaskDialogProgressBarState.Paused;
}
timerCount++;
};
};
dialogPage.Destroyed += (s, e) =>
{
dialogPageTimer.Dispose();
dialogPageTimer = null;
};
dialogPage.HyperlinkClicked += (s, e) =>
{
Console.WriteLine("Hyperlink clicked!");
TaskDialog.Show(dialog, "Clicked Hyperlink: " + e.Hyperlink, icon: TaskDialogStandardIcon.Information);
};
// Create custom buttons that are shown as command links.
TaskDialogCustomButton button1 = dialogPage.CustomButtons.Add("Change Icon + Enable Buttons ✔");
TaskDialogCustomButton button2 = dialogPage.CustomButtons.Add("Disabled Button 🎵🎶", "After enabling, can show a new dialog.");
TaskDialogCustomButton button3 = dialogPage.CustomButtons.Add("Some Admin Action…", "Navigates to a new dialog page.");
button3.ElevationRequired = true;
TaskDialogStandardIcon nextIcon = TaskDialogStandardIcon.SecuritySuccessGreenBar;
button1.Click += (s, e) =>
{
Console.WriteLine("Button1 clicked!");
// Don't close the dialog.
e.CancelClose = true;
nextIcon++;
// Set the icon and the content.
dialogPage.Icon = nextIcon;
dialogPage.Instruction = "Icon: " + nextIcon;
// Enable the "Yes" button and the 3rd button when the checkbox is set.
buttonYes.Enabled = true;
button2.Enabled = true;
};
button2.Enabled = false;
button2.Click += (s, e) =>
{
Console.WriteLine("Button2 clicked!");
// Don't close the main dialog.
e.CancelClose = true;
// Show a new Taskdialog that shows an incrementing number.
var newPage = new TaskDialogPage()
{
Text = "This is a new non-modal dialog!",
Icon = TaskDialogStandardIcon.Information,
};
TaskDialogStandardButton buttonClose = newPage.StandardButtons.Add(TaskDialogResult.Close);
TaskDialogStandardButton buttonContinue = newPage.StandardButtons.Add(TaskDialogResult.Continue);
int number = 0;
void UpdateNumberText(bool callUpdate = true)
{
// Update the instruction with the new number.
newPage.Instruction = "Hi there! Number: " + number.ToString();
}
UpdateNumberText(false);
var newPageTimer = null as Timer;
newPage.Created += (s2, e2) =>
{
newPageTimer = new Timer()
{
Enabled = true,
Interval = 200
};
newPageTimer.Tick += (s3, e3) =>
{
number++;
UpdateNumberText();
};
};
newPage.Destroyed += (s2, e2) =>
{
newPageTimer.Dispose();
newPageTimer = null;
};
buttonContinue.Click += (s2, e2) =>
{
Console.WriteLine("New dialog - Continue Button clicked");
e2.CancelClose = true;
number += 1000;
UpdateNumberText();
};
var innerDialog = new TaskDialog(newPage);
TaskDialogButton innerResult = innerDialog.Show();
Console.WriteLine("Result of new dialog: " + innerResult);
};
button3.Click += (s, e) =>
{
Console.WriteLine("Button3 clicked!");
// Don't close the dialog from the button click.
e.CancelClose = true;
// Create a new contents instance to which we will navigate the dialog.
var newContents = new TaskDialogPage()
{
Instruction = "Page 2",
Text = "Welcome to the second page!",
Icon = TaskDialogStandardIcon.SecurityShieldBlueBar,
SizeToContent = true,
CheckBox =
{
Text = "I think I agree…"
},
ProgressBar =
{
State = TaskDialogProgressBarState.Marquee
}
};
newContents.Created += (s2, e2) =>
{
Console.WriteLine("New Contents created!");
// Set a new icon after navigating the dialog. This allows us to show the
// yellow bar from the "SecurityWarningBar" icon with a different icon.
newContents.Icon = TaskDialogStandardIcon.Warning;
};
newContents.Destroyed += (s2, e2) =>
{
Console.WriteLine("New Contents destroyed!");
};
TaskDialogStandardButton buttonCancel = newContents.StandardButtons.Add(TaskDialogResult.Cancel);
buttonCancel.Enabled = false;
buttonCancel.ElevationRequired = true;
// Create a custom button that will be shown as regular button.
TaskDialogCustomButton customButton = newContents.CustomButtons.Add("My Button :)");
// Add radio buttons.
TaskDialogRadioButton radioButton1 = newContents.RadioButtons.Add("My Radio Button 1");
TaskDialogRadioButton radioButton2 = newContents.RadioButtons.Add("My Radio Button 2");
radioButton2.Checked = true;
radioButton1.CheckedChanged += (s2, e2) => Console.WriteLine(
$"Radio Button 1 CheckedChanged: RB1={radioButton1.Checked}, RB2={radioButton2.Checked}");
radioButton2.CheckedChanged += (s2, e2) => Console.WriteLine(
$"Radio Button 2 CheckedChanged: RB1={radioButton1.Checked}, RB2={radioButton2.Checked}");
newContents.CheckBox.CheckedChanged += (s2, e2) =>
{
Console.WriteLine("Checkbox CheckedChanged: " + newContents.CheckBox.Checked);
buttonCancel.Enabled = newContents.CheckBox.Checked;
};
// Now navigate the dialog.
dialog.Page = newContents;
};
TaskDialogButton result = dialog.Show();
Console.WriteLine("Result of main dialog: " + result);
}
}
}