this slowpoke moves

Create Shape on Panel

var
  Form1: TForm1;
  forma: array of TShape;    //Array to create
  formaUtil: Integer;        // Kind of shape
  Numforma: Integer;         //Number of shapes
  Izq, Arr, Ancho, alto, x1, x2, y1, y2: Integer; //Position and size of shape
  activar: Boolean;          //Tells when you are creating and sizing the shape

//

procedure TForm1.Button1Click(Sender: TObject);
begin
  formaUtil := 1;   // Rectangle
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  formaUtil := 2;   // Circle
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  formaUtil := 0;
  Numforma := 0;
  activar := False;
end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if formaUtil < 1 then Exit;
  activar  := True;              //starting draw the shape
  x1 := x;
  y1 := y;
  numforma := numforma + 1;
  setlength(forma, numforma);
  forma[numforma - 1] := TShape.Create(Panel1);
  if formaUtil = 1 then
    forma[numforma - 1].Shape := stRectangle
  else
    forma[numforma - 1].Shape := stCircle;
  forma[numforma - 1].Left   := x1;
  forma[numforma - 1].Top    := y1;
  forma[numforma - 1].Parent := Panel1;
end;

procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  x2 := x;
  y2 := y;
  forma[numforma - 1].Width := x2 - x1;
  forma[numforma - 1].Height := y2 - y1;
  formaUtil := 0;
  activar   := False;
end;

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if (formaUtil = 0) then Exit;
  if (numforma = 0) then Exit;
  if not activar then Exit;
  x2 := x;
  y2 := y;
  forma[numforma - 1].Width := x2 - x1;
  forma[numforma - 1].Height := y2 - y1;
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate