你采用动态创建Image,当你放大时,重新设置Image的Width,和Height,unit Unit1;
并把它放在Form上
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
View1: TMenuItem;
ZoomIn1: TMenuItem;
ZoomOut1: TMenuItem;
Draw1: TMenuItem;
Exit1: TMenuItem;
Panel1: TPanel;
Position1: TMenuItem;
add1: TMenuItem;
N1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure ZoomIn1Click(Sender: TObject);
procedure ZoomOut1Click(Sender: TObject);
procedure RepaintOriginalMap(Sender:TObject);
procedure PaintMap(TPa:array of Tpoint);
private
{ Private declarations }
public
{ Public declarations }
end;
const
OriginalHeight=600;
OriginalWidth=800;
var
Form1: TForm1;
Image1:TImage;
Temppa,pa:array[1..4] of TPoint;
NowWidth,NowHeight:integer;
implementation
{$R *.DFM}
procedure TForm1.PaintMap(TPa:array of Tpoint);
begin
Image1.Canvas.Brush.Color := clTeal;
Image1.Canvas.Polygon(Tpa);
end;
procedure TForm1.RepaintOriginalMap(Sender:TObject);
begin
Image1.Free;
Image1:=TImage.Create(Self);
Image1.Parent:=Form1;
Image1.Left:=0;
Image1.Top:=0;
Image1.Height:=OriginalHeight;
Image1.Width:=OriginalWidth;
NowHeight:=Image1.Height;
NowWidth:=Image1.Width;
PaintMap(Pa);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Image1:=TImage.Create(Self);
Image1.Parent:=Form1;
Image1.Left:=0;
Image1.Top:=0;
Image1.Width:=OriginalWidth;
Image1.Height:=OriginalHeight;
NowWidth:=Image1.Width;
NowHeight:=Image1.Height ;
pa[1].x:=50;
pa[1].y:=50;
pa[2].x:=50;
pa[2].y:=50;
pa[3].x:=65;
pa[3].y:=85;
pa[4].x:=120;
pa[4].y:=60;
temppa:=pa;
PaintMap(temppa);
end;
procedure TForm1.ZoomIn1Click(Sender: TObject);
var
i:integer;
begin
Image1.Free;
Image1:=TImage.Create(Self);
Image1.Parent:=Form1;
Image1.Left:=0;
Image1.Top:=0;
Image1.Height:=trunc(NowHeight*1.5);
Image1.Width:=trunc(NowWidth*1.5);
NowHeight:=Image1.Height;
NowWidth:=Image1.Width;
for i:=1 to 4 do
begin
TempPa.x:=trunc(temppa.x*1.5);
TempPa.y:=Trunc(temppa.y*1.5);
end;
paintmap(temppa)
end;
procedure TForm1.ZoomOut1Click(Sender: TObject);
var
i:integer;
begin
MyCount:=MyCount-1;
Label1.Caption:=IntToStr(MyCount);
if myCount=0 then
begin
RepaintOriginalMap(Sender)
end
else
begin
Image1.Destroy;
Image1:=TImage.Create(Self);
Image1.Parent:=Form1;
Image1.Left:=0;
Image1.Top:=0;
Image1.Height:=Trunc(NowHeight/1.5);
Image1.Width:=Trunc(NowWidth/1.5);
NowHeight:=Image1.Height;
NowWidth:=Image1.Width;
for i:=1 to 4 do
begin
Temppa.x:=trunc(Temppa.x/1.5);
TempPa.y:=trunc(Temppa.y/1.5);
end;
PaintMap(Temppa)
end;
end;
end.