📄 utubform.pas
字号:
unit uTubForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, uInterface;
type
TTubForm = class(TForm, IPhotoNotify)
Panel: TPanel;
PaintBox: TPaintBox;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PaintBoxPaint(Sender: TObject);
procedure PanelResize(Sender: TObject);
private
fPhotoMgr: IPhotoMgr;
fBmp: TBitmap;
fPID: Integer;
private
//实现IPhotoNotify接口
function SelPhoto(const photoID: Integer): Boolean;
function NewPhoto(const photoID: Integer): Boolean;
function DelPhoto(const photoID: Integer): Boolean;
function Refresh(): Boolean;
function PropChange(const photoID: Integer): Boolean;
//显示缩略图
procedure DrawBmp(bmp:TBitmap;Canvas:TCanvas; aWidth:Integer; aHeight:Integer);
public
procedure SetPhotoMgr(aphotoMgr: IPhotoMgr);
end;
var
TubForm: TTubForm;
implementation
{$R *.dfm}
{ TTubForm }
procedure TTubForm.FormCreate(Sender: TObject);
begin
fBmp := TBitmap.Create;
end;
{------------------------------------------------------------------------------}
procedure TTubForm.FormDestroy(Sender: TObject);
begin
fBmp.Free;
end;
{//////////////////////////////////////////////////////////////////////////////}
function TTubForm.DelPhoto(const photoID: Integer): Boolean;
begin
Result := True;
if fPID <> photoID then Exit;
if fPhotoMgr.GetSelPhotoID(fpid) then
begin
fPhotoMgr.GetBmp(fPID,fbmp);
PaintBox.Invalidate;
end;
end;
{------------------------------------------------------------------------------}
function TTubForm.NewPhoto(const photoID: Integer): Boolean;
begin
Result := True;
end;
{------------------------------------------------------------------------------}
function TTubForm.PropChange(const photoID: Integer): Boolean;
begin
Result := True;
end;
{------------------------------------------------------------------------------}
function TTubForm.Refresh: Boolean;
begin
Result := True;
if fPhotoMgr.GetSelPhotoID(fpid) then
begin
fPhotoMgr.GetBmp(fPID,fbmp);
PaintBox.Invalidate;
end;
end;
{------------------------------------------------------------------------------}
function TTubForm.SelPhoto(const photoID: Integer): Boolean;
begin
//读取当前选择的照片
Result := True;
if fPID = photoID then Exit;
fPID := photoID;
fPhotoMgr.GetBmp(fPID,fbmp);
PaintBox.Invalidate;
end;
{//////////////////////////////////////////////////////////////////////////////}
procedure TTubForm.SetPhotoMgr(aphotoMgr: IPhotoMgr);
begin
fPhotoMgr := aphotoMgr;
end;
{//////////////////////////////////////////////////////////////////////////////}
//画出缩略图
procedure TTubForm.DrawBmp(bmp: TBitmap; Canvas: TCanvas; aWidth, aHeight: Integer);
var
nW,nH:Integer;
begin
//比例调整
if bmp.Empty then Exit;
// nW := aHeight * bmp.Width div bmp.Height;
// nH := aWidth * bmp.Height div bmp.Width;
// if nW > aWidth then
// bmp.Canvas.StretchDraw();
end;
{------------------------------------------------------------------------------}
procedure TTubForm.PaintBoxPaint(Sender: TObject);
var
pt:TPaintBox;
begin
pt := TPaintBox(Sender);
DrawBmp(fBmp,pt.Canvas,pt.Width,pt.Height);
end;
{------------------------------------------------------------------------------}
procedure TTubForm.PanelResize(Sender: TObject);
begin
PaintBox.Invalidate;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -