4

我正在使用Application.ActivateHint(p), wherep: TPoint来显示指定位置的提示。但它总是显示在 Delphi XE2 上的实际鼠标坐标上。

请看堆栈:

Main.ApplicationEventsShowHint('Hint String Here...',True,$18FB14)
:5049c644 TCustomApplicationEvents.DoShowHint + $20
:5049d043 TMultiCaster.DoShowHint + $4B
:50454a6b TApplication.ActivateHint + $213
RxDBCtrl.TRxDBGrid.MouseMove([],934,45)

RxDBCtrl.TRxDBGrid.MouseMove我调用TApplication.ActivateHint正确的屏幕坐标作为参数。但是 onMain.ApplicationEventsShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo)的值HintInfo.HintPos与实际鼠标坐标相同。作为参数传递的值将TApplication.ActivateHint丢失。

为什么会发生这种情况?如何在 Delphi XE2 上显示所需坐标的提示?

非常感谢您的帮助!

4

2 回答 2

2

我确信有一种方法可以使用默认的 Hint 控件来实现这一点,但您可能需要查看TBalloonHint组件,它允许您在给定位置显示提示。

这是一个关于如何实现这一目标的非常简单的示例:

var B : TBalloonHint;

procedure TForm1.FormCreate(Sender: TObject);
begin
  B := TBalloonHint.Create(Self);
  B.Style := bhsStandard;
  CustomHint := B;
end;

创建窗体时,我们将 BalloonHint 组件分配给主窗体,任何将parentCustomHint属性设置为 True 的组件都将继承 CustomHint。

之后,您可以像这样简单地在给定的屏幕位置调用提示:

B.ShowHint(Point(X,Y)); {Where X & Y are Screen Coordinates}

对于简单的演示:

  1. 创建一个新的空白 VCL 项目

  2. 整合以下内容:

    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    var B : TBalloonHint;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Hint := 'Test';
      ShowHint := True;
      B := TBalloonHint.Create(Self);
      B.Style := bhsStandard;
      CustomHint := B;
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var P : TPoint;
    begin
      P := Point(X,Y);
      P := ClientToScreen(P);
      B.ShowHint(P);
    end;
    
于 2013-07-05T19:33:44.007 回答
0

问题来自以下方法:

procedure TJvDBGrid.CMHintShow(var Msg: TCMHintShow); message CM_HINTSHOW;

以及组件的新属性:

type
  TJvDBGridCellHintPosition = (gchpDefault, gchpMouse);

property CellHintPosition: TJvDBGridCellHintPosition; default gchpDefault;

为了解决这个问题,我在调用提示之前使用了以下代码:

ShowCellHint := True;
CellHintPosition := gchpDefault;

第二行是可选的。但是我在调​​试器上看到了非常奇怪的属性gchpMouse值。CellHintPosition

于 2013-07-12T16:27:15.560 回答