在Delphi/Lazarus中设置提示窗口(THintWindow)的大小 [英] Setting size of hint window (THintWindow) in Delphi/Lazarus

查看:376
本文介绍了在Delphi/Lazarus中设置提示窗口(THintWindow)的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在拉撒路做一个自定义提示.到目前为止,我已经在提示中动态加载了文本,并自定义了字体,字体大小和字体颜色.我想限制提示窗口的宽度.有任何想法吗?这是我的代码.

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;

感谢您的帮助.

推荐答案

我现在只有拉撒路(Lazarus)源和记事本,但是我将尽力向您解释

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:

  • If you assign your class name to the 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 来自基类的函数(来自 THintWindow 类),因此您应该覆盖它:
    • For getting the hint window size the application calls the 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 and
      as result return the bounds rectangle you want to have. If you wouldn't override it, the CalcHintRect 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;
      

      这篇关于在Delphi/Lazarus中设置提示窗口(THintWindow)的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆