2013-12-23 57 views

回答

8

創建自己的後代TBalloonHintTHintWindow。重寫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. 

的樣本項目中使用它:

  • 創建一個新的VCL窗體應用程序。
  • 在對象檢查器中將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. 

樣本輸出(醜陋,但它的工作原理):

Image of memo control with ugly green hint popup

+0

謝謝你,但你可以給我的代碼,我不是德爾福的專家。 – ghaek741977

+0

謝謝你肯懷特,這是非常有幫助的。 – ghaek741977

+0

Tballoonint,因爲我正在合作。 – ghaek741977