我正在尝试在组件内部的运行时临时更改提示文本,
无需更改 Hint
属性本身。
我 try catch CM_SHOWHINT
,但此事件似乎只出现在
表单,但不是组件本身。
插入 CustomHint 也不起作用,因为它需要文本
来自 Hint
属性。
我的组件是 TCustomPanel
的后代
这就是我正在尝试做的事情:
procedure TImageBtn.WndProc(var Message: TMessage);
begin
if (Message.Msg = CM_HINTSHOW) then
PHintInfo(Message.LParam)^.HintStr := 'CustomHint';
end;
我在互联网上的某个地方找到了这段代码,不幸的是它不起作用。
最佳答案
CM_HINTSHOW
确实正是您所需要的。这是一个简单的例子:
type
TButton = class(Vcl.StdCtrls.TButton)
protected
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
end;
TMyForm = class(TForm)
Button1: TButton;
end;
....
procedure TButton.CMHintShow(var Message: TCMHintShow);
begin
inherited;
if Message.HintInfo.HintControl=Self then
Message.HintInfo.HintStr := 'my custom hint';
end;
问题中的代码无法调用inherited
,这可能就是它失败的原因。或者,类声明可能省略了 WndProc
上的 override
指令。无论如何,我在这个答案中的方式更清晰。
关于delphi - delphi中拦截hint事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838372/