■ TaskDialogを表示する
[1] "Windows API Code Pack 1.1"をダウンロードする
http://code.msdn.microsoft.com/WindowsAPICodePack/Release/ProjectReleases.aspx?ReleaseId=4906
[2] その中の「Microsoft.WindowsAPICodePack.dll」をVS2010に参照設定する
[3] 「using Microsoft.WindowsAPICodePack.Dialogs;」忘れずに
サンプル
using Microsoft.WindowsAPICodePack.Dialogs;
TaskDialog taskDialog = null;
private void button1_Click(object sender, EventArgs e)
{
this.taskDialog = new TaskDialog();
this.taskDialog.OwnerWindowHandle = this.Handle;
this.taskDialog.Icon = TaskDialogStandardIcon.Error;
this.taskDialog.Caption = "題名";
this.taskDialog.InstructionText = "メッセージ(青字)";
this.taskDialog.Text = "メッセージ(黒字)";
TaskDialogStandardButtons button
= TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No;
this.taskDialog.StandardButtons = button;
this.taskDialog.DetailsExpandedLabel = "詳細メッセージ用ラベル";
this.taskDialog.DetailsExpandedText = "詳細メッセージ";
this.taskDialog.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandContent;
this.taskDialog.FooterIcon = TaskDialogStandardIcon.Shield;
this.taskDialog.Cancelable = false; // ダイアログの×アイコン非表示(ボタンにCancelを指定すると意味がないらしい)
TaskDialogResult result = taskDialog.Show();
switch (result)
{
case TaskDialogResult.Yes:
this.label1.Text = "Yes";
break;
case TaskDialogResult.No:
this.label1.Text = "No";
break;
}
}
サンプル
TaskDialog taskDialog = null;
private void button1_Click(object sender, EventArgs e)
{
this.taskDialog = new TaskDialog();
this.taskDialog.OwnerWindowHandle = this.Handle;
this.taskDialog.Icon = TaskDialogStandardIcon.Error;
this.taskDialog.Caption = "題名";
this.taskDialog.InstructionText = "メッセージ(青字)";
this.taskDialog.Text = "メッセージ(黒字)";
TaskDialogStandardButtons button
= TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No;
this.taskDialog.StandardButtons = button;
this.taskDialog.DetailsExpandedLabel = "詳細メッセージ用ラベル";
this.taskDialog.DetailsExpandedText = "詳細メッセージ";
this.taskDialog.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandContent;
this.taskDialog.FooterIcon = TaskDialogStandardIcon.Shield;
this.taskDialog.Cancelable = false;
TaskDialogCommandLink taskDialogCommandLink = new TaskDialogCommandLink();
taskDialogCommandLink.UseElevationIcon = true;
taskDialogCommandLink.Name = "taskDialogCommandLink";
taskDialogCommandLink.Instruction = "メッセージ(青字)";
taskDialogCommandLink.Text = "メッセージ(黒字)";
this.taskDialog.Controls.Add(taskDialogCommandLink);
taskDialogCommandLink.Click += new EventHandler(TaskDialogCommandLink_Click);
TaskDialogResult result = taskDialog.Show();
switch (result)
{
case TaskDialogResult.Yes:
this.label1.Text = "Yes";
break;
case TaskDialogResult.No:
this.label1.Text = "No";
break;
case TaskDialogResult.Cancel:
this.label1.Text = "Cancel";
break;
}
}
private void TaskDialogCommandLink_Click(object sender, EventArgs args)
{
this.taskDialog.Close(TaskDialogResult.Cancel);
}
■ カスタムボタンを作成する
サンプル
TaskDialog taskDialog = null;
private void button1_Click(object sender, EventArgs e)
{
this.taskDialog = new TaskDialog();
this.taskDialog.OwnerWindowHandle = this.Handle;
this.taskDialog.Icon = TaskDialogStandardIcon.Error;
this.taskDialog.Caption = "題名";
this.taskDialog.InstructionText = "メッセージ(青字)";
this.taskDialog.Text = "メッセージ(黒字)";
this.taskDialog.DetailsExpandedLabel = "詳細メッセージ用ラベル";
this.taskDialog.DetailsExpandedText = "詳細メッセージ";
this.taskDialog.ExpansionMode = TaskDialogExpandedDetailsLocation.ExpandContent;
this.taskDialog.FooterIcon = TaskDialogStandardIcon.Shield;
this.taskDialog.Cancelable = false;
TaskDialogButton taskDialogButton = new TaskDialogButton();
taskDialogButton.Name = "taskDialogButton";
taskDialogButton.Text = "カスタムボタン OK?";
taskDialogButton.Default = true;
this.taskDialog.Controls.Add(taskDialogButton);
taskDialogButton.Click += new EventHandler(TaskDialogButton_Click);
TaskDialogResult result = taskDialog.Show();
switch (result)
{
case TaskDialogResult.Yes:
this.label1.Text = "Yes";
break;
case TaskDialogResult.No:
this.label1.Text = "No";
break;
case TaskDialogResult.Cancel:
this.label1.Text = "Cancel";
break;
}
}
private void TaskDialogButton_Click(object sender, EventArgs args)
{
this.taskDialog.Close(TaskDialogResult.Ok);
}