.


:




:

































 

 

 

 





AutoSize=true. , private.

Move:Boolean; //

X0,y0:integer; //

Procedure TForm1.Image1MouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

Begin

If Button<>mbLeft then exit; // ,

X0:=X;

Y0:=Y;

Image1.Canvas.DrawFocusRect(Rect(X-5,Y-5,X+5,Y+5)); { }

Move:=true; { }

End;

procedure TForm1.Image1MouseMove (Sender: TObject; Shift: TShiftState; X,Y: Integer);

begin

if not Move then exit; // ,

Image1.Canvas.DrawFocusRect(Rect(X0-5,Y0-5,X0+5,Y0+5)); { }

Image1.Canvas.DrawFocusRect(Rect(X-5,Y-5,X+5,Y+5)); { }

X0:=X; { }

Y0:=Y;

end;

.

procedure TForm1.Image1MouseUp (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer);

begin

if not drag then exit;

Image1.Canvas.DrawFocusRect(Rect(X0-5,Y0-5,X0+5,Y0+5)); { }

Move:=false; { }

end;

, , ( drag = true). , , . .

15.

1. PazlForm.pas, Pazly .

2. :

a. .

b. , .

3. , BitMap, , . , , .

a. bmp. . g18.bmp

b. private

BitMap:TBitMap;

FileName: String;

c. OnCreate -

procedure TForm1.FormCreate(Sender: TObject);

begin

FileName:='g18.bmp'; //

BitMap:=TBitMap.Create; //

try // ,

BitMap.LoadFromFile(FileName); // BitMap

Canvas.Draw(0,0,BitMap); //

Width:=BitMap.Width*2; //

Height:=BitMap. Height* 3 div 2; //

finally // , .

end; {try}

end;

d. , , . OnDestroy( ) .

procedure TForm1.FormDestroy(Sender: TObject);

var i,j:integer;

begin

Bitmap. Free; // BitMap

end;

e. . , , Delphi, . . OnPaint.

procedure TForm1.FormPaint(Sender: TObject);

begin

if BitMap<>nil then // ,

canvas.CopyRect(canvas.ClipRect,BitMap.Canvas,canvas.ClipRect);

end;

f. . .

4. . TImage, TImage. , .

a. .

b. private

Pict:TImage; //

Picti,n:Byte; //

Paz:array [1..10,1..10] of TImage; //

c. FormCreate Picti:=0;

d.

procedure TForm1.Timer1Timer(Sender: TObject);

var i,j,w,h:integer; // , ,

vs:real;

begin

if Picti>0 then exit; // ,

Picti:=1; // ,

Pict:=TImage.Create(Self); //

Pict.Picture.LoadFromFile(FileName); //

n:=StrToInt(InputBox('', ' ', '3')); //

w:= Pict.Width div n; //

h:=Pict.Height div n; //

BitMap:=nil; //

canvas.Refresh; //

for i:=1 to n do

for j:=1 to n do begin

Paz[i,j]:=TImage.Create(Self); //

Paz[i,j].Parent:=self; //

Paz[i,j].Height:=h; //

Paz[i,j].Width:= w; //

Paz[i,j].Canvas.CopyRect(Paz[i,j].ClientRect,Pict.Canvas, Rect(w *(i-1),(j-1)*h,w * i, j*h)); // Pict, .

Paz[i,j].Visible:=true; //

Paz[i,j].Left:= w *(i-1 ); //

Paz[i,j].Top:=(j-1)*h;

Paz[i,j].DragKind:=dkDock; // , . = dkDrag .

Paz[i,j].DragMode:=dmAutomatic; //

Paz[i,j].ManualFloat(Rect(Left+Paz[i,j].Left, Top+Paz[i,j].Top,Left+Paz[i,j].Left+w, Top+Paz[i,j].Top+h)); //

Paz[i,j].ManualDock(Form1,nil,alleft); //

end; {for}

Randomize; { }

for i:=1 to n do for j:=1 to n do begin

Paz[i,j].Left:= random(Width-w);

Paz[i,j].Top:=random(Height - h);

end;

Pict.Free; //

end;

e. . .

5. ,

6. OpenDialog, .

. 16

1. . , . , .

2. .

procedure TForm1.Timer1Timer(Sender: TObject);

var i,j:integer;

vs:real;

begin

if Picti>0 then exit; // ,

Picti:=1;

Pict:=TImage.Create(Self); //

Pict.AutoSize:=true;

Pict.Picture.LoadFromFile(FileName);

n:=StrToInt(InputBox('', ' ', '3'));

w:= Pict.Width div n; //

h:=Pict.Height div n; //

BitMap:=nil;

canvas.Refresh; //

for i:=1 to n do begin

for j:=1 to n do begin

Paz[i,j]:=TImage.Create(Self); //

with Paz[i,j] do begin

Parent:=self; //

Height:=h; //

Width:= w; //

Canvas.CopyRect(Paz[i,j].ClientRect,Pict.Canvas, Rect(w *(j-1),(i-1)*h,w * j, i*h));//

Visible:=true; //

Left:= w *(i-1); //

Top:=(j-1)*h;

AutoSize:=true; //

{OnMouseDown:=Image1MouseDown;

OnMouseMove:=Image1MouseMove;

OnMouseUp:=Image1MouseUp;} //

end;

end;

end;

Randomize; //

for i:=1 to n do begin

for j:=1 to n do begin

Paz[i,j].Left:= random(Width-w*3 div 2);

Paz[i,j].Top:=random(Height - h*3 div 2);

end;

end;

Pict.Free;

end;

3. Image1 :

4. OnMouseDown

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

if button<>mbLeft then exit;

x0:=x;

y0:=y;

move:=true;

rec:=(sender as TControl).BoundsRect;

end;

x0 y0 private, , move:Boolean, rec:TRect.

5. OnMouseMove

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,

Y: Integer);

begin

if not move then exit;

Canvas.DrawFocusRect(rec);

with rec do begin

left:= Left+x-x0;

Right:=Right+x-x0;

Top:=top+y-y0;

bottom:=bottom+y-y0;

x0:=x;

y0:=y;

end;

Canvas.DrawFocusRect(rec);

end;

6. OnMouseUp

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

var l,t:integer;

begin

Canvas.DrawFocusRect(rec);

with (Sender as TControl) do begin

l:=(rec.Left +x-x0) div w * w;

t:=(rec.Top +y-y0)div h *h;

SetBounds(l,t,Width,Height);

BringToFront;

end;

move:=false;

end;

7. . . . . Image1 , . .

8. . , .

function TForm1.analiz:boolean;

var i,j:integer;

begin

Result:=false;

for i:=1 to n do

for j:=1 to n do begin

if abs((Paz[i,j].Left-Paz[1,1].Left) - (j-1)*w)>1 then exit;

if abs((Paz[i,j].Top-Paz[1,1].Top) - (i-1)*h)>1 then exit;

end;

result:=true;

end;

. TForm1.Image1MouseUp

if analiz then ShowMessage(' !');

, .





:


: 2015-05-07; !; : 368 |


:

:

.
==> ...

1602 - | 1430 -


© 2015-2024 lektsii.org - -

: 0.048 .