我在 Windows 7 64 位下运行 Delphi XE。
我加载了这些第三方组件: Virtual Trees 版本 4.8.7 TZip 版本 1.5 JVCL 3.45 Graphics32 1.9 Final GExperts 1.33 DWS DCP Crypt 版本 2.0 TeeChart Pro v2011
当鼠标悬停在 TListBox Item 上时,我想创建 PDF 的弹出“预览”图像。我想我会在我的窗口的 FormCreate 中创建一个 TForm,然后隐藏它,直到我的 TfrmMain.ListBoxMouseMove 例程上的 (ListBox.ItemIndex > -1)。
现在,我只是想掌握使用 JPEG 图像,而不是 PDF。
我注意到使用 TImage 和 OnMouseOver 相当慢。 有没有更快的方法来做到这一点?也许使用 JEDI 组件?
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, PicUnit, jpeg, GraphUtil;
type
TfrmMain = class(TForm)
lst: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure lstClick(Sender: TObject);
procedure lstMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
procedure lstMouseLeave(Sender: TObject);
public
popPic: TfrmPic;
ImagePaths: TStringList;
LastHoover: Integer;
procedure LoadImages(Item: Integer);
end;
var
frmMain: TfrmMain;
Implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
popPic := TfrmPic.Create(nil);
ImagePaths := TStringList.Create;
LastHoover := -1;
end;
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
popPic.Free;
ImagePaths.Free;
end;
procedure TfrmMain.lstClick(Sender: TObject);
begin
if (lst.ItemIndex > -1) then
begin
popPic.Show;
end { ItemIndex > -1 }
else
popPic.Hide;
end;
procedure TfrmMain.lstMouseLeave(Sender: TObject);
begin
frmPic.Hide;
end;
procedure TfrmMain.lstMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
HooverItem : Integer;
begin
{ Returns -1 if the mouse is NOT over a item on the list }
HooverItem := lst.ItemAtPos (Point (X, Y), True);
if (HooverItem > -1) and (HooverItem <> LastHoover) then
begin
{ Match the image onto the screen }
frmPic.Left := frmMain.ClientToScreen(Point(X, Y)).X;
frmPic.Top := frmMain.ClientToScreen(Point(X, Y)).Y;
LoadImages(HooverItem);
LastHoover := HooverItem;
if (ImagePaths.Count > 0) then
begin
{ TImage Method }
frmPic.imgStd.Stretch := True;
frmPic.imgStd.Picture.LoadFromFile (ImagePaths [0]);
frmPic.Show;
frmMain.SetFocus;
end
else
frmPic.Hide;
end
else
if (HooverItem = -1) then
frmPic.Hide;
end;
procedure TfrmMain.LoadImages(Item: Integer);
begin
{ Clear off the existing list }
ImagePaths.Clear;
if (Item = 0) then
begin
ImagePaths.Add ('C:\Floating Image Demo\0.jpeg');
ImagePaths.Add ('C:\Floating Image Demo\1.jpeg');
end
else
if (Item = 1) then
begin
ImagePaths.Add ('C:\Floating Image Demo\1.jpeg');
ImagePaths.Add ('C:\Floating Image Demo\0.jpeg');
end;
end;
end.