with ListView1.Items.Add do
begin
ImageIndex:=imagelist1.Count-1;
caption:=ImageFileList.GetCurFileName;
end;
ProgressBar1.Position:=i;
application.ProcessMessages;
end;
finally
listview1.Items.EndUpdate;
ProgressBar1.Visible:=false;
end;
screen.Cursor:= crDefault;
IsRefreshImageFinished:=true;
end;
7.过程DrawPanel的代码如下:
//在canvas上画一个Panel
procedure DrawPanel(canvas:TCanvas;Left,Top,Width,Height:integer;PanelType:integer);
var
Right,Bottom:integer;
LeftTopColor,RightBottomColor:TColor;
begin
//凸起的panel
if PanelType=RaisedPanel then
begin
LeftTopColor:=clwhite;
RightBottomColor:=clgray;
end
else //凹下去的panel
begin
LeftTopColor:=clgray;
RightBottomColor:=clwhite;
end;
Right:=Left+width;
Bottom:=Top+Height;
Canvas.Pen.Width:=1;
Canvas.Pen.Color:=LeftTopColor;
Canvas.MoveTo(Right,Top);
Canvas.lineTo(Left,Top);
Canvas.LineTo(Left,bottom);
Canvas.Pen.Color:=RightBottomColor;
Canvas.lineTo(Right,Bottom);
Canvas.lineTo(Right,Top);
end;
8.接下来我们在ListView1的OnSelectItem事件里添加代码:
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
//当ShellTreeView1目录改变时 会激发此事件,
if listview1.SelCount=0 then exit;
//当窗体释放时也会激发此事件
//ImageFileList.GetFileCount=0 后再 ImageFileList.SetIndex(item.Index);
//会引起异常
if ImageFileList.GetFileCount=0 then exit;
ImageFileList.SetIndex(item.Index);
ShowPreImageFit(ImageFileList.GetCurFullFileName);
end;
9.其中过程ShowImageFit的代码比较罗嗦,如下所示:
//image1在Panel1中居中显示图片文件ImageFileName
procedure TForm1.ShowPreImageFit(const ImageFileName: string);
begin
Image1.Visible:=false;
if IsJpgFile(ImageFileName) then
begin
JpgToBmp(ImageFileName,PreViewJpg,PreViewBmp);
Image1.Picture.Bitmap:=PreViewBmp;
end
else