delphi - 如何在 OnHint 事件处理程序中检测提示发送者控件?

标签 delphi delphi-10.3-rio hints

在 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 中显示 TApplication.Hint 文本。 。如果设置StatusBar的AutoHint属性设置为 true 则 StatusBar 可以自动显示 TApplication.Hint 更新。您只需要确保没有分配 OnHint 处理程序,否则 AutoHint 将无法工作(OnShowHint 也可以) .

关于delphi - 如何在 OnHint 事件处理程序中检测提示发送者控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61149931/

相关文章:

delphi - DeviceIoControl - GetLastError : ERROR_NOACCESS - 998

delphi - 在delphi中更改文本颜色(控制台应用程序)

hints - Vimperator:使用不带 <CR> 的提示(可能通过强制唯一性)

android - TextInputLayout 和 EditText 提示可见

delphi - 我可以保证在表单销毁后执行自定义完成代码吗?

string - delphi中如何将字符串中的一个字符转换为字符

excel - Delphi 导出到 Excel - IDE 中编译代码出现错误

json - Delphi 在运行时更改 JSONMarshalledAttribute

Delphi 10.3.1 编译器生成的代码在编译为 64 位时会发出异常

oracle - 对 View 使用提示?