After long searches on the Internet, with the information I found, I created this code to change the hint font size of my control. But when I try to assign Message.HintInfo.HintWindowClass:=HintWin;
it give me error: E2010 Incompatible types: 'THintWindowClass' and 'THintWindow'. If I try to typecast THintWindowClass(HitWin)
I get access violation. What should I do ?
In this similar question, Remy Lebeau says: "To change the layout of the hint, you can derive a new class from THintWindow and assign that class type to the THintInfo.HintWindowClass field.".... But I do not understand what he meant.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyButton = class(TButton)
protected
HintWin: THintWindow;
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
MyButton: TMyButton;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyButton:=TMyButton.Create(Form1);
MyButton.Parent:=Form1;
MyButton.Caption:='Test';
MyButton.Left:=100;
MyButton.Top:=100;
MyButton.ShowHint:=true;
end;
constructor TMyButton.Create(AOwner: TComponent);
begin
inherited;
HintWin:=THintWindow.Create(self);
HintWin.Canvas.Font.Size:=24;
end;
destructor TMyButton.Destroy;
begin
HintWin.Free;
inherited;
end;
procedure TMyButton.CMHintShow(var Message: TCMHintShow);
begin
inherited;
Message.HintInfo.HintWindowClass:=HintWin;
Message.HintInfo.HintStr:='My custom hint';
end;
end.
As others mentioned in the comments, you can use a custom hint window like this:
Using the following declaration, you have a bigger hint font only for your button:
Explanation: in
THinWindow.Create
, the font is initialized with the value ofScreen.HintFont
- so after the call toinherited
, you can customize your hint font.A final note: because of the current implementation (D 10.2.3 Tokyo) of
THintWindow.Paint
, you can not change the font color of the hint text, because the value is taken fromScreen.HintFont.Color
every time the hint window is painted. In such cases, you'll have to overridePaint
and draw the complete hint window yourself.