When using TballoonHint
, I need it more personalized in colors, shape, transparency and animated appearance, how can I do that?
问问题
2085 次
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 回答