1

When using TballoonHint, I need it more personalized in colors, shape, transparency and animated appearance, how can I do that?

4

1 回答 1

11

TBalloonHint创建您自己的or的后代THintWindow。覆盖NCPaint绘制外边缘(非客户区)和CalcHintRect(如果需要)的方法,并提供您自己的Paint方法来绘制您希望它出现的内部。

然后Application.HintWindowClass在调用 .dpr 之前将其分配给 .dpr 文件Application.Run

这是一个(非常小的)示例,它只使用绿色背景绘制标准提示窗口。

将此保存为MyHintWindow.pas

unit MyHintWindow;

interface

uses
  Windows, Controls;

type
  TMyHintWindow=class(THintWindow)
  protected
    procedure Paint; override;
    procedure NCPaint(DC: HDC); override;
  public
    function CalcHintRect(MaxWidth: Integer; const AHint: string; AData: Pointer): TRect;
      override;
  end;

implementation

uses
  Graphics;

{ TMyHintWindow }

function TMyHintWindow.CalcHintRect(MaxWidth: Integer; 
  const AHint: string; AData: Pointer): TRect;
begin
  // Does nothing but demonstrate overriding.
  Result := inherited CalcHintRect(MaxWidth, AHint, AData);
  // Change window size if needed, using Windows.InflateRect with Result here
end;

procedure TMyHintWindow.NCPaint(DC: HDC);
begin
  // Does nothing but demonstrate overriding. Changes nothing.
  // Replace drawing of non-client (edges, caption bar, etc.) with your own code
  // here instead of calling inherited. This is where you would change shape 
  // of hint window
  inherited NCPaint(DC);
end;

procedure TMyHintWindow.Paint;
begin
  // Draw the interior of the window. This is where you would change inside color,
  // draw icons or images or display animations. This code just changes the
  // window background (which it probably shouldn't do here, but is for demo 
  // purposes only.
  Canvas.Brush.Color := clGreen;
  inherited;
end;

end.

使用它的示例项目:

  • 创建一个新的 VCL 表单应用程序。
  • 在 Object Inspector中将Form1.ShowHint属性设置为。True
  • 将任何控件(TEdit例如 a )放在表单上,​​并在其Hint属性中放置一些文本。
  • 使用Project->View Source菜单显示项目源代码。

将指示的行添加到项目源中:

program Project1;

uses
  Forms,
  MyHintWindow,                // Add this line
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  HintWindowClass := TMyHintWindow;      // Add this line
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

示例输出(丑陋,但有效):

带有丑陋的绿色提示弹出窗口的备忘录控件的图像

于 2013-12-23T19:40:39.480 回答