0

I'd like to create some padding to all hints shown in my Delphi 12 application. I am already setting the global HintWindowClass to a custom class derived from THintWindow, and I thought its constructor may create that padding. But everything I did so far has no effect on the hint window:

HintWindowClass := TMyHintWindow;

...

constructor TMyHintWindow.Create(AOwner: TComponent);
begin
  inherited;
  AlignWithMargins := True;
  Margins.Left := 10;
  Margins.Right := 10;
  Padding.Left := 10;
  Padding.Right := 10;
end;

Do I have to manipulate the canvas in some way?

2
  • 2
    The hint window does not use controls inside to display the hint, but rather paints it on the canvas. Therefore anything tweaked with alignments won't work. Better override CalcHintRect and Paint. Commented Feb 16 at 17:00
  • Thank you, that works indeed! One needs to increase the surrounding rect in .CalcHintRect and move the text rect in .Paint. Commented Feb 16 at 18:02

1 Answer 1

2

The hint window does not use controls inside to display the hint, but rather paints it on the canvas. Therefore anything tweaked with alignments won't work. Better override CalcHintRect and Paint.

To avoid copying most of the inherited code of THintWindow you can use this approach:

  TMyHintWindow = class(THintWindow)
  private
    FPainting: Boolean;
  protected
    function GetClientRect: TRect; override;
    procedure Paint; override;
  public
    function CalcHintRect(MaxWidth: Integer; const AHint: string; AData: TCustomData): TRect; override;
  end;

function TMyHintWindow.CalcHintRect(MaxWidth: Integer; const AHint: string; AData: TCustomData): TRect;
begin
  Result := inherited;
  Result.Width := Result.Width + 2*ScaleValue(10);
  Result.Height := Result.Height + 2*ScaleValue(10);
end;

function TMyHintWindow.GetClientRect: TRect;
begin
  Result := inherited;
  if FPainting then
    Result.Inflate(-ScaleValue(10), -ScaleValue(10));
end;

procedure TMyHintWindow.Paint;
begin
  FPainting := True;
  try
    inherited;
  finally
    FPainting := False;
  end;
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.