Delphi 列表框中的图像预览

Delphi 列表框中的图像预览,delphi,image,listbox,preview,Delphi,Image,Listbox,Preview,当我将鼠标悬停在文件名列表框中的项目上时,如何显示图像的预览(几乎像提示一样)?我尝试过显示表单并加载图像,但当预览表单显示时,列表框失去焦点,这意味着当我移动鼠标时,当我转到列表中的下一项时,预览图像不会改变 谢谢,彼得 根据TOndrej的回答,我尝试实现自定义THintWindow,但Canvas.StretchDraw没有绘制作为参数发送的位图。有什么想法吗?文本显示正常 procedure TFormMain.DisplayPreview(HintImage: TBitmap); v

当我将鼠标悬停在文件名列表框中的项目上时,如何显示图像的预览(几乎像提示一样)?我尝试过显示表单并加载图像,但当预览表单显示时,列表框失去焦点,这意味着当我移动鼠标时,当我转到列表中的下一项时,预览图像不会改变

谢谢,彼得


根据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;
1) 是否像对话框(模式窗口)一样显示预览表单?如果是,则将其更改为非模式窗口。
2) 记得在预览窗体显示后将焦点设置回父窗口,这样,具有listbox的父窗体将具有焦点,并将鼠标移动事件传递到listbox。


向您致意。

对我来说,您似乎需要一个自定义提示窗口。为此,您应该编写一个新的
THintWindow
子体,并通过将新类分配给
Forms
单元中的
HintWindowClass
全局变量,将其全局设置为整个应用程序,或者编写自己的列表框子体,在其中处理
CM\u HINTSHOW
消息,并将新的提示窗口类分配给
HintInfo.HintWindowClass
。(HintInfo指向VCL在
CM\u HINTSHOW
消息中传递给控件的记录。)