如何在Delphi上使用Application.ActivateHint显示提示? [英] How to show hint using Application.ActivateHint on Delphi?

查看:279
本文介绍了如何在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;

这篇关于如何在Delphi上使用Application.ActivateHint显示提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆