TAction には OnHint イベントがありますが、残念ながら OnHideHint イベントはありません。これには、次の欠点があります。アクションに関連付けられたツールボタンやその他のコントロールがあります。マウスがそのようなコントロールの上にあるときはいつでも、Action のヒントが StatusBar に表示されます。(StatusBar の AutoHint プロパティを True に設定しました)。しかし、マウスがツールボタンから離れると、ステータスバーの以前のカスタム テキスト (ヒントからではない) は自動的に復元されません! これで、フォーム上のすべてのコントロールに対して OnMouseLeave イベント ハンドラーを記述して、StatusBar のカスタム テキストを復元できますが、これは面倒です。StatusBar の以前のテキストを自動的に復元するものはありませんか? TAction の OnHideHint イベントが理想的です。
2 に答える
2
これがデフォルトの動作です。AutoHint が True の場合、ステータス バーは自動的にヒント アクションに応答し、最初のパネルにヒントのテキストの長いバージョンを表示します。
あなたが抱えている問題は、マウスでコントロールを離れると、基本的に別のウィンドウに入るということです。それは親コントロールです。その親には Hint 文字列値が割り当てられていないため、HintAction は空の文字列に更新されます。
表示するヒントがないときにデフォルト値を返したい場合は、TApplicationEventsコンポーネントをフォームにドロップし、次のように TApplication.OnHint イベントを使用します。
var
OriginalPanelText : String = 'BLA';
procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
if StatusBar1.SimplePanel or (StatusBar1.Panels.Count = 0)
then
if Application.Hint <> ''
then
StatusBar1.SimpleText := Application.Hint
else
StatusBar1.SimpleText := OriginalPanelText
else
if Application.Hint <> ''
then
StatusBar1.Panels[0].Text := Application.Hint
else
StatusBar1.Panels[0].Text := OriginalPanelText;
end;
于 2013-06-10T22:23:00.493 に答える
0
AutoHint
魔法はすべてで起こりますTStatusBar.ExecuteAction
。コードがステータスバーのテキストを空に設定することをヒントが示しなくなったとき。次のように動作を変更できます。
type
TStatusBar = class(ComCtrls.TStatusBar)
private
FRestoreTextAfterHintAction: string;
public
function ExecuteAction(Action: TBasicAction): Boolean; override;
end;
function TStatusBar.ExecuteAction(Action: TBasicAction): Boolean;
var
HintText: string;
begin
if AutoHint and not (csDesigning in ComponentState) and
(Action is THintAction) and not DoHint then begin
HintText := THintAction(Action).Hint;
if SimplePanel or (Panels.Count=0) then begin
if HintText='' then begin
SimpleText := FRestoreTextAfterHintAction;
end else begin
FRestoreTextAfterHintAction := SimpleText;
SimpleText := HintText;
end;
end else begin
if HintText='' then begin
Panels[0].Text := FRestoreTextAfterHintAction;
end else begin
FRestoreTextAfterHintAction := Panels[0].Text;
Panels[0].Text := HintText;
end;
end;
Result := True;
end else begin
Result := inherited ExecuteAction(Action);
end;
end;
復元するテキストを格納するために、かなり粗雑なインターポーザー クラスと壊れやすいインスタンス変数を使用しました。必要に応じて、これをもう少し堅牢にすることができます。上記のコードは、少なくともフックを追加する必要がある場所を示しています。
于 2013-06-11T11:01:53.277 に答える