我正在尝试在 Lazarus 中进行自定义提示。到目前为止,我已经动态加载了提示中的文本,并自定义了字体、字体大小和字体颜色。我想限制提示窗口的宽度。有任何想法吗?这是我的代码。
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;
感谢您的帮助。
最佳答案
我现在只有 Lazarus 源代码和记事本,但我会尝试向您解释 THintWindow
使用它是因为理解它是最重要的:
- 如果您将类名分配给
HintWindowClass
全局变量,那么您可以说注册您的提示窗口类以供应用程序全局使用。然后,每次应用程序要显示提示时,它将使用您的提示窗口类并调用您的重写函数以及基THintWindow
中的函数。你没有覆盖的类。以下是如何注册您的提示窗口类以在应用程序范围内使用:
HintWindowClass := TExHint;
- 为了获取提示窗口大小,应用程序调用
CalcHintRect
每当要显示提示时都会起作用。要自行调整提示窗口大小,您需要重写此函数,
结果返回您想要的边界矩形。如果您不覆盖它,CalcHintRect
将使用基类(来自THintWindow
类)的函数,因此您应该重写它:
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;
关于delphi - 在Delphi/Lazarus中设置提示窗口(THintWindow)的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11472874/