0
使用TballoonHint
時,我需要更加個性化的顏色,形狀,透明度和動態外觀,我該怎麼做?我想要更個性化的氣球提示(背景顏色/圓角/透明)
使用TballoonHint
時,我需要更加個性化的顏色,形狀,透明度和動態外觀,我該怎麼做?我想要更個性化的氣球提示(背景顏色/圓角/透明)
創建自己的後代TBalloonHint
或THintWindow
。重寫NCPaint
方法繪製外邊緣(非客戶區域)和CalcHintRect
(如果需要),並提供自己的Paint
方法繪製內部,如您希望的那樣出現。
然後在調用Application.Run
之前,將其分配給您的.dpr文件中的Application.HintWindowClass
。
下面是一個(非常小的)例子,它除了用綠色背景繪製標準提示窗口外,什麼都不做。
保存爲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.
樣本輸出(醜陋,但它的工作原理):
謝謝你,但你可以給我的代碼,我不是德爾福的專家。 – ghaek741977
謝謝你肯懷特,這是非常有幫助的。 – ghaek741977
Tballoonint,因爲我正在合作。 – ghaek741977