あなたはドキュメントを見つけることができない場合は、write it:
タスクダイアログのHello Worldの
with TTaskDialog.Create(Self) do
try
Caption := 'My Application';
Title := 'Hello World!';
Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' +
'in the Microsoft Windows Vista operating system. Am I not adorable?';
CommonButtons := [tcbClose];
Execute;
finally
Free;
end;
Caption
を示すテキストですウィンドウのタイトルバー、Title
がヘッダーで、Text
はダイアログの本体です。言うまでもなく、Execute
はタスクダイアログを表示し、その結果を以下に示します。 (私たちは、セクションまたは2にCommonButtons
プロパティに戻ります。)
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog1.png
ビーイングのWindows XPの下で実行されている場合はもちろん、タスクダイアログは、プログラムがクラッシュします行儀シチズン
、タスクダイアログAPIはありません。また、ビジュアルテーマが無効になっている場合は動作しません。そのような場合は、旧式のMessageBox
に固執する必要があります。したがって、実際のアプリケーションでは、我々はこの記事の残りの部分では
if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled then
with TTaskDialog.Create(Self) do
try
Caption := 'My Application';
Title := 'Hello World!';
Text := 'I am a TTaskDialog, that is, a wrapper for the Task Dialog introduced ' +
'in the Microsoft Windows Vista operating system. Am I not adorable?';
CommonButtons := [tcbClose];
Execute;
finally
Free;
end
else
MessageBox(Handle,
'I am an ordinary MessageBox conveying the same message in order to support' +
'older versions of the Microsoft Windows operating system (XP and below).',
'My Application',
MB_ICONINFORMATION or MB_OK);
を行う必要があるだろう、我々は後方互換性のtaxが支払われていることを前提とし、代わりに単独のダイアログタスクに集中します。
ダイアログの種類。モーダルは
CommonButtons
プロパティは、タイプTTaskDialogCommonButtons
のこの特性は、(我々は後で行いますとどのボタンも、手動で追加されていない場合)ダイアログに表示ボタンを決定
TTaskDialogCommonButton = (tcbOk, tcbYes, tcbNo, tcbCancel, tcbRetry, tcbClose);
TTaskDialogCommonButtons = set of TTaskDialogCommonButton;
として定義されている結果。ユーザーがこれらのボタンのいずれかをクリックすると、対応するTModalResult
の値は、Execute
が返されるとすぐにModalResult
プロパティに格納されます。 MainIcon
プロパティは、ダイアログに表示されるアイコンを決定します。もちろん、ボタンのセットのようにダイアログの性質を反映する必要があります。正式には整数MainIcon
は、tdiNone
,tdiWarning
,tdiError
,tdiInformation
およびtdiShield
のいずれかの値に設定できます。以下
with TTaskDialog.Create(Self) do
try
Caption := 'My Application';
Title := 'The Process';
Text := 'Do you want to continue even though [...]?';
CommonButtons := [tcbYes, tcbNo];
MainIcon := tdiNone; // There is no tdiQuestion
if Execute then
if ModalResult = mrYes then
beep;
finally
Free;
end;
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog2.png
残りのアイコンの種類(シールド、警告、エラー、それぞれ)のサンプルである:
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog3.png
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog4.png
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog5.png
最後に、DefaultButton
プロパティを使用して、ダイアログボックスのデフォルトボタンを設定できることがわかります。
with TTaskDialog.Create(Self) do
try
Caption := 'My Application';
Title := 'The Process';
Text := 'Do you want to continue even though [...]?';
CommonButtons := [tcbYes, tcbNo];
DefaultButton := tcbNo;
MainIcon := tdiNone;
if Execute then
if ModalResult = mrYes then
beep;
finally
Free;
end;
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog6.png
カスタムボタン
あなたは、タスクダイアログにカスタムボタンを追加することができます。実際には、CommonButtons
プロパティを空のセットに設定し、カスタムボタン(およびボタンの数に制限はありません)に完全に依存することができます。下記の実際の例では、このようなダイアログ・ボックスを示しています
with TTaskDialog.Create(self) do
try
Title := 'Confirm Removal';
Caption := 'Rejbrand BookBase';
Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Remove';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Keep';
ModalResult := mrNo;
end;
MainIcon := tdiNone;
if Execute then
if ModalResult = mrYes then
DoDelete;
finally
Free;
end
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog7.png
コマンドは、タスクダイアログのボタンは、コマンドリンクすることができ、古典的なプッシュボタンの代わりに
をリンクします。これは、tfUseCommandLinks
フラグ(Flags
)を設定することによって実現されます。今、あなたはまた、CommandLinkHint
(ごとのボタン)プロパティを設定することができます。
with TTaskDialog.Create(self) do
try
Title := 'Confirm Removal';
Caption := 'Rejbrand BookBase';
Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Remove';
CommandLinkHint := 'Remove the book from the catalogue.';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Keep';
CommandLinkHint := 'Keep the book in the catalogue.';
ModalResult := mrNo;
end;
Flags := [tfUseCommandLinks];
MainIcon := tdiNone;
if Execute then
if ModalResult = mrYes then
DoDelete;
finally
Free;
end
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog8.png
tfAllowDialogCancellation
フラグが近いシステムメニュー項目(タイトルバーのボタンを復元します - 実際には、それが全体を復元しますシステムメニュー)。
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog9.png
あなたは、ユーザーがAクリックした後にのみ表示されるテキストの一部(旧)を追加するプロパティExpandedText
とExpandedButtonCaption
を使用することができ、エンドユーザー
で技術的な詳細を投げないでください。ボタン(後者のプロパティのテキストの左側)をクリックしてリクエストします。
with TTaskDialog.Create(self) do
try
Title := 'Confirm Removal';
Caption := 'Rejbrand BookBase';
Text := Format('Are you sure that you want to remove the book file named "%s"?', [FNameOfBook]);
CommonButtons := [];
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Remove';
CommandLinkHint := 'Remove the book from the catalogue.';
ModalResult := mrYes;
end;
with TTaskDialogButtonItem(Buttons.Add) do
begin
Caption := 'Keep';
CommandLinkHint := 'Keep the book in the catalogue.';
ModalResult := mrNo;
end;
Flags := [tfUseCommandLinks, tfAllowDialogCancellation];
ExpandButtonCaption := 'Technical information';
ExpandedText := 'If you remove the book item from the catalogue, the corresponding *.book file will be removed from the file system.';
MainIcon := tdiNone;
if Execute then
if ModalResult = mrYes then
DoDelete;
finally
Free;
end
下の画像は、ユーザーがボタンをクリックして追加の詳細を表示した後のダイアログを示しています。
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog10.png
あなたがtfExpandFooterArea
フラグを追加する場合、追加のテキストではなくフッタに表示されます。いずれの場合で
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog11.png
、すでに詳細を示すダイアログが開いせることができますtfExpandedByDefault
フラグを追加して拡張しました。
カスタムアイコン
あなたはCustomMainIcon
プロパティで使用するTIcon
をtfUseHiconMain
フラグを使用して指定することで、タスクダイアログで任意のカスタムアイコンを使用することができます。
with TTaskDialog.Create(self) do
try
Caption := 'About Rejbrand BookBase';
Title := 'Rejbrand BookBase';
CommonButtons := [tcbClose];
Text := 'File Version: ' + GetFileVer(Application.ExeName) + #13#10#13#10'Copyright © 2011 Andreas Rejbrand'#13#10#13#10'http://english.rejbrand.se';
Flags := [tfUseHiconMain, tfAllowDialogCancellation];
CustomMainIcon := Application.Icon;
Execute;
finally
Free;
end
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog12.png
ハイパーリンク
だけtfEnableHyperlinks
フラグを追加する場合でも、(Text
、Footer,
とExpandedText
に)ダイアログで、HTMLのようなハイパーリンクを使用することができます。
with TTaskDialog.Create(self) do
try
Caption := 'About Rejbrand BookBase';
Title := 'Rejbrand BookBase';
CommonButtons := [tcbClose];
Text := 'File Version: ' + GetFileVer(Application.ExeName) + #13#10#13#10'Copyright © 2011 Andreas Rejbrand'#13#10#13#10'<a href="http://english.rejbrand.se">http://english.rejbrand.se</a>';
Flags := [tfUseHiconMain, tfAllowDialogCancellation, tfEnableHyperlinks];
CustomMainIcon := Application.Icon;
Execute;
finally
Free;
end
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog13.png
ただし、リンクをクリックしても何も起こりません。リンクの動作は手動で実装する必要があります。これはもちろん、良いことです。これを行うには、TNotifyEvent
のOnHyperlinkClicked
イベントに返信してください。リンク(要素のhref、つまり)のURLをTTaskDialog
のURL
パブリックプロパティに格納されています
procedure TForm1.TaskDialogHyperLinkClicked(Sender: TObject);
begin
if Sender is TTaskDialog then
with Sender as TTaskDialog do
ShellExecute(0, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with TTaskDialog.Create(self) do
try
Caption := 'About Rejbrand BookBase';
Title := 'Rejbrand BookBase';
CommonButtons := [tcbClose];
Text := 'File Version: ' + GetFileVer(Application.ExeName) + #13#10#13#10'Copyright © 2011 Andreas Rejbrand'#13#10#13#10'<a href="http://english.rejbrand.se">http://english.rejbrand.se</a>';
Flags := [tfUseHiconMain, tfAllowDialogCancellation, tfEnableHyperlinks];
OnHyperlinkClicked := TaskDialogHyperlinkClicked;
CustomMainIcon := Application.Icon;
Execute;
finally
Free;
end
end;
あなたが作成するFooter
とFooterIcon
プロパティを使用することができフッター
フッター。 icon
プロパティは、MainIcon
プロパティと同じ値を受け入れます。 tfUseHiconFooter
フラグとCustomFooterIcon
プロパティを使用して
with TTaskDialog.Create(self) do
try
Caption := 'My Application';
Title := 'A Question';
Text := 'This is a really tough one...';
CommonButtons := [tcbYes, tcbNo];
MainIcon := tdiNone;
FooterText := 'If you do this, then ...';
FooterIcon := tdiWarning;
Execute;
finally
Free;
end
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog14.png
、あなたがあなた自身のメインのアイコンを選択することができますと同じように、フッターに任意のカスタムアイコンを使用することができます。 Aチェックボックス
VerificationText
文字列プロパティを使用して
、あなたはタスクダイアログのフッターにあるチェックボックスを追加することができます。チェックボックスのキャプションがプロパティです。
とTTaskDialog.Create(self)do try キャプション:= 'My Application'; タイトル:= '質問'; テキスト:= 'これは本当に厳しいものです...'; CommonButtons:= [tcbYes、tcbNo]; MainIcon:= tdiNone; VerificationText:= '自分の選択を記憶する'; 実行します。 最終的に 無料;
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog15.png
終了あなたは、チェックボックスが最初にtfVerificationFlagChecked
フラグを指定することで確認することができます。残念ながら、TTaskDialog
のVCL実装のバグ(?)により、Execute
が返されたときにこのフラグがインクルードされても、チェックボックスの最終状態は反映されません。チェックボックスを追跡するために、アプリケーションは、このように初期状態を覚えているし、チェックボックスの状態は、ダイアログのモダリティ中に変更されるたびにトリガされた各OnVerificationClicked
イベントへの応答として内部フラグをトグルする必要があります。
ラジオボタンはカスタムプッシュボタン(またはコマンドリンクボタン)を追加する方法に似た方法で実装することができ
ラジオボタン:
with TTaskDialog.Create(self) do
try
Caption := 'My Application';
Title := 'A Question';
Text := 'This is a really tough one...';
CommonButtons := [tcbOk, tcbCancel];
MainIcon := tdiNone;
with RadioButtons.Add do
Caption := 'This is one option';
with RadioButtons.Add do
Caption := 'This is another option';
with RadioButtons.Add do
Caption := 'This is a third option';
if Execute then
if ModalResult = mrOk then
ShowMessage(Format('You chose %d.', [RadioButton.Index]));
finally
Free;
end
Sample of a TTaskDialog http://specials.rejbrand.se/TTaskDialog/taskdialog16.png
でも、私は、特定の問題の解決策を見つけた: 'TTaskDialogButtonItem(Buttons.Add)とのキャプションを開始します:= 'キャプション'; CommandLinkHint:= '説明';それはあまりにも明白ではありませんでしたが、それは機能します... –
自分自身、私はそれを使うのはかなり簡単なWin32 API関数に対して直接書く方が簡単だと思います。 –
@David:はい、おそらく私は代わりにそれを行うべきです。 –