1

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

谢谢,彼得。


根据 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;
4

2 回答 2

2

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

于 2009-04-20T11:47:54.150 回答
1

1)如果是,您是否像对话框(模态窗口)一样显示预览表单,然后将其更改为非模态窗口。
2)一旦预览表单出现,请记住将焦点设置回您的父窗口,这样您的具有列表框的父表单将获得焦点,并将鼠标移动事件传递给列表框。

此致。

于 2009-04-20T11:40:58.457 回答