当我将鼠标悬停在文件名列表框中的项目上时,如何显示图像的预览(几乎像提示)?我尝试显示表单并加载图像,但是当预览表单显示时,我失去了列表框的焦点,这意味着当我移动鼠标时,当我转到列表中的下一个项目时预览图像不会改变.
谢谢,彼得。
根据 TOndrej 的回答,我尝试实现自定义 THintWindow,但 Canvas.StretchDraw 不会绘制作为参数发送的位图。有什么想法为什么不呢?文本正常显示。
procedure TFormMain.DisplayPreview(HintImage: TBitmap);
var
CustomHint: THintWindow;
Rect: TRect;
MousePoint: TPoint;
begin
*{
Based on Source: http://www.chami.com/tips/delphi/112996D.html
}*
GetCursorPos(MousePoint);
with Rect do
begin
// set the position and size of the hint window
Left := MousePoint.X;
Top := MousePoint.Y;
Right := Left + 50;
Bottom := Top + 25;
end;
CustomHint := THintWindow.Create(Self);
try
with CustomHint do
begin
// set the background color
//Color := clNone;
**Canvas.StretchDraw(Rect, HintImage);**
ActivateHint(Rect, 'Hint');
Application.ProcessMessages;
//
// perform your tasks here
// before closing the hint window
//
Sleep(500);
ReleaseHandle;
end;
finally
if Assigned(CustomHint) then
CustomHint.Free;
end;
end;