如何在Delphi上使用Application.ActivateHint显示提示?
问题描述:
我有以下代码尝试显示提示:
I have the following code trying to show a hint:
procedure TMyGrid.OnGridMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
aPoint: TPoint;
begin
inherited;
//Application.Hint := 'Hint Text';
//Application.ShowHint := True;
Grid.Hint := 'Hint Text';
Grid.ShowHint := True;
aPoint.X := X;
aPoint.Y := Y;
Application.ActivateHint(aPoint);
end;
但是没有提示出现.怎么了?
But there is no hint appears. What's wrong?
答
ActivateHint
wants your point in screen coordinates, not in client coordinates.
来自文档:
ActivateHint将控件或菜单项定位在CursorPos指定的位置,其中 CursorPos代表屏幕坐标(以像素为单位).找到控件后,ActivateHint在提示窗口中显示控件的提示.
ActivateHint locates the control or menu item at the position specified by CursorPos, where CursorPos represents a screen coordinates in pixels. After locating the control, ActivateHint displays the control's Hint in a hint window.
因此,您必须像这样更改方法:
So, you have to change your method like this:
procedure TMyGrid.OnGridMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
aPoint: TPoint;
begin
inherited;
//Application.Hint := 'Hint Text';
Grid.Hint := 'Hint Text';
Grid.ShowHint := True;
aPoint.X := X;
aPoint.Y := Y;
aPoint := ClientToScreen(aPoint);
Application.ActivateHint(aPoint);
end;