?? 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 + -