如何在hint中加入图片呢?
如何在hint中加入一个ICO图片呢? 我hint的文字是从xml文件读的,如果能在xml文件中加图片也可以,但是两者我都不会加,
求教各位!
[解决办法]
这个,基本上~~很难~~ 帮顶!!
[解决办法]
unit HintEx;
interface
uses
Windows, SysUtils, Classes, Graphics, Controls, Forms;
type
TGraphicHintWindow = class(THintWindow)
constructor Create(AOwner: TComponent); override;
private
FActivating: Boolean;
public
procedure ActivateHint(Rect: TRect; const AHint: string); override;
protected
procedure Paint; override;
published
property Caption;
end;
implementation
constructor TGraphicHintWindow.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with Canvas.Font do
begin
Name := 'Arial ';
Style := Style + [fsBold];
Color := clBlack;
end;
end;
procedure TGraphicHintWindow.Paint;
var
R: TRect;
bmp: TBitmap;
begin
R := ClientRect;
Inc(R.Left, 2);
Inc(R.Top, 2);
bmp := TBitmap.Create;
bmp.LoadfromFile( 'Hint.bmp ');
with Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := clsilver;
Pen.Color := clgray;
Rectangle(0, 0, 18, R.Bottom + 1);
Draw(2, (R.Bottom div 2) - (bmp.Height div 2), bmp);
end;
bmp.Free;
Color := clWhite;
Canvas.Brush.Style := bsClear;
Canvas.TextOut(20, (R.Bottom div 2) - (Canvas.Textheight(Caption) div 2), Caption);
end;
procedure TGraphicHintWindow.ActivateHint(Rect: TRect; const AHint: string);
begin
FActivating := True;
try
Caption := AHint;
Inc(Rect.Bottom, 14);
Rect.Right := Rect.Right + 20;
UpdateBoundsRect(Rect);
if Rect.Top + Height > Screen.DesktopHeight then
Rect.Top := Screen.DesktopHeight - Height;
if Rect.Left + Width > Screen.DesktopWidth then
Rect.Left := Screen.DesktopWidth - Width;
if Rect.Left < Screen.DesktopLeft then Rect.Left := Screen.DesktopLeft;
if Rect.Bottom < Screen.DesktopTop then Rect.Bottom := Screen.DesktopTop;
SetWindowPos(Handle, HWND_TOPMOST, Rect.Left, Rect.Top, Width, Height,
SWP_SHOWWINDOW or SWP_NOACTIVATE);
Invalidate;
finally
FActivating := False;
end;
end;
end.
//用法
procedure TForm1.FormCreate(Sender: TObject);
begin
HintWindowClass := TGraphicHintWindow;
Application.ShowHint := False;
Application.ShowHint := True;
end;
[解决办法]
HintWindowClass := TGraphicHintWindow
这句什么意思?可否解释一下啊?
[解决办法]
好贴,随便帮顶
Use THintWindow to display a Help Hint pop-up window directly from an application. Override THintWindow to customize the window that appears automatically for controls with their ShowHint property set to true. After overriding THintWindow to create a new derived type, assign the new type to the global HintWindowClass variable at application startup, so that the new hint window type is used for Help Hints.
The hint window 's BiDiMode is always set to the BiDiMode of the control that activates it. If the mode is bdRightToLeft, then the hint is left-aligned to the cursor.
[解决办法]
可以自己画啊,取鼠标坐标,然后贴Image
[解决办法]
HintWindowClass := TGraphicHintWindow
这句什么意思?可否解释一下啊?
//------------------------
THintWindowClass = class of THintWindow;//THintWindowClass是一个类引用
HintWindowClass: THintWindowClass;
可以赋一个类名给一个类引用变量