默认的Hint窗口展现如下:
这种情况下可以操作有窗口的背景颜色,字体样式
Application.Color
有的时候仅仅是文字满足不了我们的需求,比例如下格式:
这个时候就应该执行以下步骤:
1.新建一个单元,基层自:THintWindow;
2.重写THintWindow的PCPaint方法或者Paint方法来绘制自己想要的格式;
3.将全局变量HintWindowClass赋值为你所写的类(这步必须要在Application创建form之前);
请参见如下代码:
自定义类
unit MyHintWindow; interface uses Forms,Windows,Messages,Controls,Themes,Classes,Graphics; type TMyHintWindow = class(THintWindow) protected procedure NCPaint(DC: HDC); override; procedure Paint; override; end; TMyHintWindowClass = class of TMyHintWindow; implementation var tempBmp:TBitMap; procedure init; begin tempBmp := TBitmap.Create; tempBmp.LoadFromFile('Chrysanthemum.bmp'); end; { TMyHintWindow } procedure TMyHintWindow.NCPaint(DC: HDC); begin inherited; //在这里写入绘画非客户区的代码 end; procedure TMyHintWindow.Paint; var clientRect:TRect; begin Self.Width := 500; Self.Height := 500; clientRect:= GetClientRect; clientRect.Bottom := clientRect.Top + 3; Canvas.Brush.Color := clred; Canvas.FillRect(clientRect); Canvas.Brush.Color := clWhite; clientRect:= GetClientRect; clientRect.Top := clientRect.Top + 3; Canvas.FillRect(clientRect); Canvas.TextOut(100,3,Caption); Canvas.Draw(0,18,tempBmp); end; initialization init; finalization tempBmp.Free; end.
工程单元代码如下:
program Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1}, MyHintWindow in 'MyHintWindow.pas'; {$R *.res} begin Application.HintColor := $000000; Application.HintHidePause := 10000; HintWindowClass := TMyHintWindow; Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end.