使用TballoonHint
时,我需要在颜色,形状,透明度和动画外观方面更加个性化,我该怎么做?
答案 0 :(得分:10)
创建自己的TBalloonHint
或THintWindow
后代。覆盖NCPaint
方法以绘制外边(非客户区)和CalcHintRect
(如果需要),并提供您自己的Paint
方法来绘制内部,如您所愿出现。
然后在调用Application.HintWindowClass
之前将其分配到.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.
使用它的示例项目:
Form1.ShowHint
属性设置为True
。TEdit
),并在其Hint
属性中放入一些文本。将指示的行添加到项目源:
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.
示例输出(丑陋但可行):