2013-12-23 3 views

ответ

8

Создайте собственный потомок 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. 

Проект образец использовать его:

  • Создать новый VCL формы приложения.
  • Установите объект Form1.ShowHint на номер True в инспекторе объектов.
  • Оставьте любой элемент управления (например, TEdit) на форме и поместите в него текст 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. 

Пример вывода (уродливый, но он работает):

Image of memo control with ugly green hint popup

+0

Спасибо, но могли бы вы дать мне код, Я не специалист в Delphi. – ghaek741977

+0

Спасибо, Кен Уайт, это очень полезно. – ghaek741977

+0

Как насчет Tballoonint, потому что я работаю. – ghaek741977