Thema: Image bewegen

Einzelnen Beitrag anzeigen

Jonski

Registriert seit: 28. Nov 2009
Ort: Hessen
75 Beiträge
 
Delphi 7 Personal
 
#26

Re: Image bewegen

  Alt 28. Nov 2009, 23:41
Jaja ich weiß was ich falsch gemacht habe.
Hier nochmal eine verbesserte Variante nur bewegt sich der Kreis nicht mehr:
Delphi-Quellcode:
nit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Image2: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);

var Bitmap1,Bitmap2:TBitmap;
begin
Bitmap1:=TBitmap.Create;
  try
    Bitmap1.Width:=Image1.Width;
    Bitmap1.Height:=Image1.Height;
    Bitmap1.Canvas.pen.color:=clGreen;
    Bitmap1.Canvas.pen.width:=10;
    Bitmap1.Canvas.Ellipse(5,5,50,50);
    Image1.Picture.Assign(Bitmap1);
  finally
    Bitmap1.Free;
  end;

Bitmap2:=TBitmap.Create;
  try
    Bitmap2.Width:=Image2.Width;
    Bitmap2.Height:=Image2.Height;
    Bitmap2.Canvas.pen.color:=clBlue;
    Bitmap2.Canvas.pen.width:=10;
    Bitmap2.Canvas.Rectangle(10,10,1000,15);
    Image2.Picture.Assign(Bitmap2);
  finally
    Bitmap2.Free;
  end;

  with Image1 do
  begin
  transparent:=true;
  end;

  with Image2 do
  begin
  transparent:=true;
  end;

end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

if Image1.Left - 10 > Image2.Left then
  begin
  Image1.Left := Image1.Left - 10;
  end
else begin
  case Key of
    VK_LEFT: Image1.Left := Image1.Left - 10;
  end;
end;

if Image1.Left + 10 > Image2.Left then
  begin
  Image1.Left := Image1.Left + 10;
  end
else begin
  case Key of
    VK_RIGHT: Image1.Left := Image1.Left + 10;
  end;
end;

if Image1.Top - 10 > Image2.Top then
  begin
  Image1.Top := Image1.Top - 10;
  end
else begin
  case Key of
    VK_DOWN: Image1.Top := Image1.Top - 10;
  end;
end;

if Image1.Top + 10 > Image2.Top then
  begin
  Image1.Top := Image1.Top + 10;
  end
else begin
  case Key of
    VK_UP: Image1.Top := Image1.Top + 10;
  end;
end;
end;

end.
Jonas
MFG Jonski
  Mit Zitat antworten Zitat