回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,301 +1,151 @@
|
|
1
1
|
閲覧者向けに雑実装^^;
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
閉じるボタンは消していませんが、押しても閉じません。
|
6
|
-
|
7
4
|
コードからキャンセルとかアイコン表示とかいろいろあるでしょうが、わたしは使わないのでこれ以上凝る気はありません(ダイアログ嫌いなので^^;
|
8
5
|
|
6
|
+
```xml
|
7
|
+
<Window
|
8
|
+
x:Class="Questions374184.MainWindow"
|
9
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
10
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
11
|
+
Width="800"
|
12
|
+
Height="450">
|
13
|
+
<StackPanel>
|
14
|
+
<Button Content="TaskDialog" Click="Button_Click" />
|
15
|
+
<Button Content="ProgressDialog" Click="Button_Click_1" />
|
16
|
+
</StackPanel>
|
17
|
+
</Window>
|
18
|
+
```
|
19
|
+
```cs
|
20
|
+
using System;
|
21
|
+
using System.Threading;
|
22
|
+
using System.Threading.Tasks;
|
23
|
+
using System.Windows;
|
24
|
+
using Microsoft.WindowsAPICodePack.Dialogs;
|
9
25
|
|
26
|
+
namespace Questions374184
|
27
|
+
{
|
28
|
+
public partial class MainWindow : Window
|
29
|
+
{
|
30
|
+
public MainWindow() => InitializeComponent();
|
10
31
|
|
32
|
+
private void Button_Click(object sender, RoutedEventArgs e)
|
33
|
+
{
|
11
|
-
|
34
|
+
var dialog = new TaskDialog
|
35
|
+
{
|
36
|
+
Caption = "Caption",
|
37
|
+
InstructionText = "InstructionText",
|
38
|
+
Text = "Text",
|
39
|
+
ProgressBar = new TaskDialogProgressBar(),
|
40
|
+
};
|
12
41
|
|
42
|
+
IProgress<int> progress = new Progress<int>(i =>
|
43
|
+
{
|
44
|
+
dialog.ProgressBar.Value = i;
|
13
|
-
<
|
45
|
+
if (100 <= i) dialog.Close();
|
46
|
+
});
|
14
47
|
|
48
|
+
Task.Run(() =>
|
49
|
+
{
|
15
|
-
|
50
|
+
for (var i = 0; i <= 100; i++)
|
51
|
+
{
|
52
|
+
Thread.Sleep(100);
|
53
|
+
progress.Report(i);
|
54
|
+
}
|
55
|
+
});
|
16
56
|
|
17
|
-
|
57
|
+
dialog.Show();
|
58
|
+
}
|
18
59
|
|
60
|
+
private void Button_Click_1(object sender, RoutedEventArgs e)
|
61
|
+
{
|
62
|
+
var dialog = new ProgressDialog
|
63
|
+
{
|
64
|
+
Caption = "Caption",
|
19
|
-
|
65
|
+
InstructionText = "InstructionText",
|
66
|
+
Text = "Text",
|
67
|
+
Owner = this,
|
68
|
+
};
|
20
69
|
|
70
|
+
Task.Run(() =>
|
71
|
+
{
|
72
|
+
for (var i = 0; i <= 100; i++)
|
73
|
+
{
|
74
|
+
Thread.Sleep(100);
|
21
|
-
|
75
|
+
dialog.Progress.Report(i);
|
76
|
+
}
|
77
|
+
});
|
22
78
|
|
23
|
-
Height="450">
|
24
|
-
|
25
|
-
|
79
|
+
dialog.ShowDialog();
|
26
|
-
|
27
|
-
<Button Content="TaskDialog" Click="Button_Click" />
|
28
|
-
|
29
|
-
<Button Content="ProgressDialog" Click="Button_Click_1" />
|
30
|
-
|
31
|
-
</StackPanel>
|
32
|
-
|
33
|
-
|
80
|
+
}
|
34
|
-
|
81
|
+
}
|
82
|
+
}
|
35
83
|
```
|
36
84
|
|
85
|
+
```xml
|
86
|
+
<Window
|
87
|
+
x:Class="Questions374184.ProgressDialog"
|
88
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
89
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
90
|
+
Title="ProgressDialog"
|
91
|
+
Width="380"
|
92
|
+
ResizeMode="NoResize"
|
93
|
+
SizeToContent="Height"
|
94
|
+
WindowStartupLocation="CenterOwner">
|
95
|
+
<StackPanel Margin="10">
|
96
|
+
<TextBlock
|
97
|
+
x:Name="instructionText"
|
98
|
+
Margin="5"
|
99
|
+
Foreground="#FF003399"
|
100
|
+
Text="InstructionText" />
|
101
|
+
<TextBlock
|
102
|
+
x:Name="text"
|
103
|
+
Margin="5"
|
104
|
+
Text="Text" />
|
105
|
+
<ProgressBar
|
106
|
+
x:Name="progressBar"
|
107
|
+
Height="20"
|
108
|
+
Margin="5" />
|
109
|
+
</StackPanel>
|
110
|
+
</Window>
|
111
|
+
```
|
37
|
-
```
|
112
|
+
```cs
|
38
|
-
|
39
113
|
using System;
|
40
|
-
|
41
|
-
using System.
|
114
|
+
using System.ComponentModel;
|
42
|
-
|
43
115
|
using System.Threading.Tasks;
|
44
|
-
|
45
116
|
using System.Windows;
|
46
117
|
|
118
|
+
namespace Questions374184
|
119
|
+
{
|
120
|
+
public partial class ProgressDialog : Window
|
121
|
+
{
|
122
|
+
public string Caption { get => Title; set => Title = value; }
|
123
|
+
public string InstructionText { get => instructionText.Text; set => instructionText.Text = value; }
|
124
|
+
public string Text { get => text.Text; set => text.Text = value; }
|
47
|
-
u
|
125
|
+
public IProgress<int> Progress { get; }
|
48
126
|
|
127
|
+
public ProgressDialog()
|
128
|
+
{
|
129
|
+
InitializeComponent();
|
49
130
|
|
50
|
-
|
51
|
-
namespace Questions374184
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
public partial class MainWindow : Window
|
56
|
-
|
57
|
-
{
|
58
|
-
|
59
|
-
|
131
|
+
Progress = new Progress<int>(i =>
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
private void Button_Click(object sender, RoutedEventArgs e)
|
64
|
-
|
65
|
-
{
|
66
|
-
|
67
|
-
var dialog = new TaskDialog
|
68
|
-
|
69
132
|
{
|
70
|
-
|
71
|
-
Caption = "Caption",
|
72
|
-
|
73
|
-
InstructionText = "InstructionText",
|
74
|
-
|
75
|
-
Text = "Text",
|
76
|
-
|
77
|
-
ProgressBar = new TaskDialogProgressBar(),
|
78
|
-
|
79
|
-
};
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
IProgress<int> progress = new Progress<int>(i =>
|
84
|
-
|
85
|
-
{
|
86
|
-
|
87
|
-
|
133
|
+
progressBar.Value = i;
|
88
|
-
|
89
|
-
if (100 <= i)
|
134
|
+
if (100 <= i) Close();
|
90
|
-
|
91
135
|
});
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
Task.Run(() =>
|
96
|
-
|
97
|
-
{
|
98
|
-
|
99
|
-
for (var i = 0; i <= 100; i++)
|
100
|
-
|
101
|
-
{
|
102
|
-
|
103
|
-
Thread.Sleep(100);
|
104
|
-
|
105
|
-
progress.Report(i);
|
106
|
-
|
107
|
-
}
|
108
|
-
|
109
|
-
});
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
dialog.Show();
|
114
|
-
|
115
136
|
}
|
116
137
|
|
117
|
-
|
118
|
-
|
119
|
-
pr
|
138
|
+
protected override void OnClosing(CancelEventArgs e)
|
120
|
-
|
121
139
|
{
|
122
|
-
|
123
|
-
var dialog = new ProgressDialog
|
124
|
-
|
125
|
-
{
|
126
|
-
|
127
|
-
Caption = "Caption",
|
128
|
-
|
129
|
-
InstructionText = "InstructionText",
|
130
|
-
|
131
|
-
Text = "Text",
|
132
|
-
|
133
|
-
Owner = this,
|
134
|
-
|
135
|
-
};
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
Task.Run(() =>
|
140
|
-
|
141
|
-
{
|
142
|
-
|
143
|
-
for (var i = 0; i <= 100; i++)
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
Thread.Sleep(100);
|
148
|
-
|
149
|
-
|
140
|
+
e.Cancel = progressBar.Value < 100;
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
});
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
dialog.ShowDialog();
|
158
|
-
|
159
141
|
}
|
160
|
-
|
161
142
|
}
|
162
|
-
|
163
143
|
}
|
164
|
-
|
165
144
|
```
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
```xaml
|
170
|
-
|
171
|
-
<Window
|
172
|
-
|
173
|
-
x:Class="Questions374184.ProgressDialog"
|
174
|
-
|
175
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
176
|
-
|
177
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
178
|
-
|
179
|
-
Title="ProgressDialog"
|
180
|
-
|
181
|
-
Width="380"
|
182
|
-
|
183
|
-
ResizeMode="NoResize"
|
184
|
-
|
185
|
-
SizeToContent="Height"
|
186
|
-
|
187
|
-
WindowStartupLocation="CenterOwner">
|
188
|
-
|
189
|
-
<StackPanel Margin="10">
|
190
|
-
|
191
|
-
<TextBlock
|
192
|
-
|
193
|
-
x:Name="instructionText"
|
194
|
-
|
195
|
-
Margin="5"
|
196
|
-
|
197
|
-
Foreground="#FF003399"
|
198
|
-
|
199
|
-
Text="InstructionText" />
|
200
|
-
|
201
|
-
<TextBlock
|
202
|
-
|
203
|
-
x:Name="text"
|
204
|
-
|
205
|
-
Margin="5"
|
206
|
-
|
207
|
-
Text="Text" />
|
208
|
-
|
209
|
-
<ProgressBar
|
210
|
-
|
211
|
-
x:Name="progressBar"
|
212
|
-
|
213
|
-
Height="20"
|
214
|
-
|
215
|
-
Margin="5" />
|
216
|
-
|
217
|
-
</StackPanel>
|
218
|
-
|
219
|
-
</Window>
|
220
|
-
|
221
|
-
```
|
222
|
-
|
223
|
-
```C#
|
224
|
-
|
225
|
-
using System;
|
226
|
-
|
227
|
-
using System.ComponentModel;
|
228
|
-
|
229
|
-
using System.Threading.Tasks;
|
230
|
-
|
231
|
-
using System.Windows;
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
namespace Questions374184
|
236
|
-
|
237
|
-
{
|
238
|
-
|
239
|
-
public partial class ProgressDialog : Window
|
240
|
-
|
241
|
-
{
|
242
|
-
|
243
|
-
public string Caption { get => Title; set => Title = value; }
|
244
|
-
|
245
|
-
public string InstructionText { get => instructionText.Text; set => instructionText.Text = value; }
|
246
|
-
|
247
|
-
public string Text { get => text.Text; set => text.Text = value; }
|
248
|
-
|
249
|
-
public IProgress<int> Progress { get; }
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
public ProgressDialog()
|
254
|
-
|
255
|
-
{
|
256
|
-
|
257
|
-
InitializeComponent();
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
Progress = new Progress<int>(i =>
|
262
|
-
|
263
|
-
{
|
264
|
-
|
265
|
-
progressBar.Value = i;
|
266
|
-
|
267
|
-
if (100 <= i) Close();
|
268
|
-
|
269
|
-
});
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
protected override void OnClosing(CancelEventArgs e)
|
276
|
-
|
277
|
-
{
|
278
|
-
|
279
|
-
e.Cancel = progressBar.Value < 100;
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
```
|
288
|
-
|
289
|
-
|
290
145
|
|
291
146
|
対比のために入れただけなので、WindowsAPICodePackを入れる必要はないです。
|
292
147
|
|
293
|
-
|
294
|
-
|
295
148
|
わたしが使用したのは↓で、マニュフェストでコモンコントロールを有効にする必要があります。
|
296
|
-
|
297
149
|
[NuGet Gallery | WindowsAPICodePack-Core 1.1.2](https://www.nuget.org/packages/WindowsAPICodePack-Core/1.1.2)
|
298
150
|
|
299
|
-
|
300
|
-
|
301
151
|
[視覚スタイルを有効にする - Win32 apps | Microsoft Docs](https://docs.microsoft.com/ja-jp/windows/win32/controls/cookbook-overview)
|