I am trying to make a custom hint in Lazarus. So far I have dynamically loaded the text in the hint, and customized the font face, font size, and font color. I would like to limit the width of the hint window. Any ideas? Here is my code.
type
TExHint = class(THintWindow)
constructor Create(AOwner: TComponent); override;
...
constructor TExHint.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with Canvas.Font do
begin
Name := 'Hanuman';
Size := Size + 3;
end;
//Canvas.Width := ;
end;
Thanks for any help.
I have only Lazarus source and notepad now, but I'll try to explain you how the THintWindow
is used since it's the most important to understand:
HintWindowClass
global variable, then you let's say register your hint window class for global usage by the application. Then every time the application will going to show hint, it will use your hint window class and call your overriden functions along with the functions from the base THintWindow
class you didn't override. Here is how to register your hint window class for use in a scope of the application:
HintWindowClass := TExHint;
CalcHintRect
function whenever the hint is going to be shown. To adjust the hint window size by your own you need to override this function andCalcHintRect
function from the base class (from the THintWindow
class) would be used, so you should override it:
type
TExHint = class(THintWindow)
public
constructor Create(AOwner: TComponent); override;
function CalcHintRect(MaxWidth: Integer; const AHint: String;
AData: Pointer): TRect; override;
end;
constructor TExHint.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with Canvas.Font do
begin
Name := 'Hanuman';
Size := Size + 3;
end;
end;
function TExHint.CalcHintRect(MaxWidth: Integer; const AHint: String;
AData: Pointer): TRect;
begin
// here you need to return bounds rectangle for the hint
Result := Rect(0, 0, SomeWidth, SomeHeight);
end;