THintWindow it's a run-time (no design-time is provided) descendant of TCustomForm class, with a special support from Widgetset (TWSHintWindow).
Special considerations:
- by default THintWindow
- when shown WS prevents the HintWindow from acquiring focus. (TCustomForm are shown and are receiving focus right away)
Examples
editTHintWindow does not autosize by default, the .Autosize property does nothing.
The .Show method steals the focus in Windows, so some of the .Activate... methods are preferable.
The example below illustrates how to show a properly sized THintWindow.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, Types;
type
{ TForm1 }
TForm1 = class(TForm)
Edit1: TEdit;
HintWindow : THintWindow;
Timer1: TTimer;
procedure Edit1MouseEnter(Sender: TObject);
procedure Edit1MouseLeave(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure UpdateHint(aCaption : string);
private
public
end;
var
Form1: TForm1;
HintWindowCaption : String;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.UpdateHint(aCaption : string);
var
mRect : trect;
Location : tpoint;
begin
Location := point(HintWindow.Left,HintWindow.Top);
if (HintWindow <> nil) then mRect := HintWindow.CalcHintRect(0, aCaption ,nil);
Offsetrect(mRect, Location.X,Location.Y);
HintWindow.ActivateHint(mRect,aCaption);
end;
procedure TForm1.Edit1MouseEnter(Sender: TObject);
begin
HintWindow := THintWindow.Create(Self);
HintWindow.Left := Mouse.CursorPos.X;
HintWindow.Top := Mouse.CursorPos.Y + 4;
end;
procedure TForm1.Edit1MouseLeave(Sender: TObject);
begin
if assigned(HintWindow) then
FreeAndNil(HintWindow);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (HintWindow = nil) then exit;
UpdateHint ('Hellow!' + #13#10 + 'Здрасти!' + #13#10 + IntToStr(GetTickCount64));
end;
end.