如何在 OnHint 事件处理程序中检测 Hint sender-control?
How to detect Hint sender-control in OnHint event-handler?
在 Delphi 10.3.3 Windows VCL 应用程序中,在 TApplicationEvents
组件的 OnHint
事件处理程序中,我在状态中显示当前提示-栏:
procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
statMain.SimpleText := Application.Hint;
end;
但是,我想添加一些包含特定 运行 时间数据的特定文本,具体取决于发送提示的控件。
遗憾的是,Sender
参数没有提供该信息。
那么如何检测哪个控件发送了提示?
OnHint
事件不提供对有关显示提示的控件的任何信息的访问。
但是,OnShowHint
事件确实如此,您可以在该事件中根据需要完全自定义提示:
procedure TForm1.ApplicationEvents1ShowHint(var HintStr: string;
var CanShow: boolean; var HintInfo: THintInfo);
begin
if HintInfo.HintControl = DesiredControl then
begin
// customize HintStr, and/or HintInfo fields, as needed...
end;
end;
procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
statMain.SimpleText := Application.Hint;
end;
HintInfo
提供各种提示信息,您可以自定义:
HintControl
The name of the control for which hint processing is occurring.
HintWindowClass
The class of the hint-window control. The default is THintWindow, but you can specify any class derived from THintWindow. Use this field if you want to substitute a custom hint window for THintWindow.
HintPos
The default position in screen coordinates of the top-left corner of the hint window. Change where the window appears by changing this value.
HintMaxWidth
The maximum width of the hint window before word wrapping begins. By default, the value is the width of the screen (the Width property of the global Screen variable).
HintColor
The background color of the Hint window.
CursorRect
The rectangle the user's mouse pointer must be in for the hint window to appear. The default value for CursorRect is the client rectangle of the control. Change this value so that a single control can be divided into several hint regions. When the user moves the mouse pointer outside the rectangle, the hint window disappears.
CursorPos
The location of the mouse pointer within the control.
ReshowTimeout
How long the hint system should wait before asking about the hint status again. By default, this field is zero, indicating that the hint status will not change. Setting it to a non-zero value will cause the hint to act, after the requested milliseconds have elapsed, as if the user moved the mouse outside the hint rectangle and back in. This can be used to either put off hint processing for a period of time, or to allow the hint to be updated periodically.
HideTimeout
The number of milliseconds to show the hint. By default, it is set to the value of the Application variable's HintHidePause property.
HintStr
The string to be displayed in the hint window. This allows an OnHint event handler to modify the contents of a hint before it is displayed. By default, it contains the value returned by the GetShortHint function when passed the value of the Application variable's Hint property.
HintData
Additional data to be passed to the hint-window control. Use this field in conjunction with HintWindowClass.
此外,仅供参考,您不需要使用 TApplication(Event).OnHint
事件来将 TStatusBar
. If you set the StatusBar's AutoHint
属性 中的 TApplication.Hint
文本显示为 true 然后 StatusBar可以自动显示 TApplication.Hint
更新。您只需要确保没有分配 OnHint
处理程序,否则 AutoHint
将无法工作(不过 OnShowHint
没问题)。
在 Delphi 10.3.3 Windows VCL 应用程序中,在 TApplicationEvents
组件的 OnHint
事件处理程序中,我在状态中显示当前提示-栏:
procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
statMain.SimpleText := Application.Hint;
end;
但是,我想添加一些包含特定 运行 时间数据的特定文本,具体取决于发送提示的控件。
遗憾的是,Sender
参数没有提供该信息。
那么如何检测哪个控件发送了提示?
OnHint
事件不提供对有关显示提示的控件的任何信息的访问。
但是,OnShowHint
事件确实如此,您可以在该事件中根据需要完全自定义提示:
procedure TForm1.ApplicationEvents1ShowHint(var HintStr: string;
var CanShow: boolean; var HintInfo: THintInfo);
begin
if HintInfo.HintControl = DesiredControl then
begin
// customize HintStr, and/or HintInfo fields, as needed...
end;
end;
procedure TForm1.ApplicationEvents1Hint(Sender: TObject);
begin
statMain.SimpleText := Application.Hint;
end;
HintInfo
提供各种提示信息,您可以自定义:
HintControl
The name of the control for which hint processing is occurring.HintWindowClass
The class of the hint-window control. The default is THintWindow, but you can specify any class derived from THintWindow. Use this field if you want to substitute a custom hint window for THintWindow.HintPos
The default position in screen coordinates of the top-left corner of the hint window. Change where the window appears by changing this value.HintMaxWidth
The maximum width of the hint window before word wrapping begins. By default, the value is the width of the screen (the Width property of the global Screen variable).HintColor
The background color of the Hint window.CursorRect
The rectangle the user's mouse pointer must be in for the hint window to appear. The default value for CursorRect is the client rectangle of the control. Change this value so that a single control can be divided into several hint regions. When the user moves the mouse pointer outside the rectangle, the hint window disappears.CursorPos
The location of the mouse pointer within the control.ReshowTimeout
How long the hint system should wait before asking about the hint status again. By default, this field is zero, indicating that the hint status will not change. Setting it to a non-zero value will cause the hint to act, after the requested milliseconds have elapsed, as if the user moved the mouse outside the hint rectangle and back in. This can be used to either put off hint processing for a period of time, or to allow the hint to be updated periodically.HideTimeout
The number of milliseconds to show the hint. By default, it is set to the value of the Application variable's HintHidePause property.HintStr
The string to be displayed in the hint window. This allows an OnHint event handler to modify the contents of a hint before it is displayed. By default, it contains the value returned by the GetShortHint function when passed the value of the Application variable's Hint property.HintData
Additional data to be passed to the hint-window control. Use this field in conjunction with HintWindowClass.
此外,仅供参考,您不需要使用 TApplication(Event).OnHint
事件来将 TStatusBar
. If you set the StatusBar's AutoHint
属性 中的 TApplication.Hint
文本显示为 true 然后 StatusBar可以自动显示 TApplication.Hint
更新。您只需要确保没有分配 OnHint
处理程序,否则 AutoHint
将无法工作(不过 OnShowHint
没问题)。