Cara Menggeser Gambar Dengan Delphi7



Buka aplikasi Delphi7 dan siapkan formnya, isi dengan  paintbox, grupbox, 1 tombol button, beberapa tombol bitbutton untuk arah seperti pada gambar...



kemudian masukan coding berikut :

unit Unit1;

interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, buttons, Stdctrls, extCtrls;

type

  TForm1 = class(TForm)

    GroupBox1: TGroupBox;

    GroupBox2: TGroupBox;

    PaintBox1: TPaintBox;

    BitBtn2: TBitBtn;

    BitBtn3: TBitBtn;

    BitBtn4: TBitBtn;

    BitBtn5: TBitBtn;

    BitBtn7: TBitBtn;

    BitBtn8: TBitBtn;

    BitBtn9: TBitBtn;

    BitBtn10: TBitBtn;

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

    procedure BitBtn7Click(Sender: TObject);

    procedure BitBtn5Click(Sender: TObject);

    procedure BitBtn3Click(Sender: TObject);

    procedure BitBtn9Click(Sender: TObject);

    procedure BitBtn2Click(Sender: TObject);

    procedure BitBtn10Click(Sender: TObject);

    procedure BitBtn8Click(Sender: TObject);

    procedure BitBtn4Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

var

  Form1: TForm1;

  tx,x1,y1,x2,y2:integer;

implementation

{$R *.dfm}

procedure TForm1.BitBtn10Click(Sender: TObject);

begin

with paintbox1 do

begin

          //condong kanan bawah

tx:=10;

x1:=x1+tx;

y1:=y1+tx;

x2:=x2+tx;

y2:=y2+tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn2Click(Sender: TObject);

begin

with paintbox1 do

begin

          //condong kiri atas

tx:=10;

x1:=x1-tx;

y1:=y1-tx;

x2:=x2-tx;

y2:=y2-tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn3Click(Sender: TObject);

begin

with paintbox1 do

begin

        //atas

tx:=10;

y1:=y1-tx;

y2:=y2-tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn4Click(Sender: TObject);

begin

with paintbox1 do

begin

          //condong kanan atas

tx:=10;

x1:=x1+tx;

y1:=y1-tx;

x2:=x2+tx;

y2:=y2-tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn5Click(Sender: TObject);

begin

with paintbox1 do

begin

          //kiri

tx:=10;

x1:=x1-tx;

x2:=x2-tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn7Click(Sender: TObject);

begin

with paintbox1 do

begin

           //kanan

tx:=10;

x1:=x1+tx;

x2:=x2+tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn8Click(Sender: TObject);

begin

with paintbox1 do

begin

          //condong kiri bawah

tx:=10;

x1:=x1-tx;

y1:=y1+tx;

x2:=x2-tx;

y2:=y2+tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.BitBtn9Click(Sender: TObject);

begin

with paintbox1 do

begin

          //bawah

tx:=10;

y1:=y1+tx;

y2:=y2+tx;

paintbox1.Refresh;

canvas.Ellipse(x1,y1,x2,y2);

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

with paintbox1 do

begin

            //proses

x1:=100;

y1:=100;

x2:=200;

y2:=200;

paintbox1.refresh;

canvas.Brush.color:=clred;

canvas.Ellipse(x1,y1,x2,y2);

//bintang

canvas.Brush.Color:=clblue;

canvas.pen.color:=clyellow;

canvas.Polygon([point(150,100),point(135,140),point(100,140),point(130,155),point(120,190),point(150,170),point(180,190),point(170,155),point(200,140),point(165,140)]);

//garis

//canvas.Moveto(150,100);

//canvas.Lineto(150,200);

end;

end;

end.

0 Response to "Cara Menggeser Gambar Dengan Delphi7"

Post a Comment