also what do you mean by remove the green check and add the green check on canvas pixel?
I gave you a snippet of code in which I explained that.
(See the comments in that snippet)
oh because i want to do i:= 1 to x so i can put any number in the, but i can not do that, right..?I thought i can't do that with the tshape.
You can do it if you create the TShapes dynamically.
You're correct if you put the TShape in the designer you have to know the number of boxes.
But if you create the TShapes in FormCreate you can do it in code.
Something like this:
type
TForm1 = class(TForm)
//...
private
{ private declarations }
MyBoxes: array of TShape; // <----- add this to your forms private section
public
//...
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
SetLength(MyBoxes, 7); // reserve 7 spots for the array
for i := 0 to 6 do // dynamic arrays are 0-based
begin
MyBoxes[i] := TShape.Create(Self);
MyBoxes[i].Parent := Self;
MyBoxes[i].Left := 25 { left } + (20 * i) + (5 * i);
MyBoxes[i].Top := 20;
MyBoxes[i].Height := 20;
MyBoxes[i].Width := 20;
MyBoxes[i].Shape := stSquare;
MyBoxes[i].Brush.Color := clGreen;
end;
end;
And if you want to check if your cursor (b) touches any of the boxes you can do this:
uses lclintf; // <-- you need to add this directly under implementation
//...
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//...
for i := 0 to 6 do
begin
if MyBoxes[i].Brush.Color = clGreen then // only act when box is green
if RectInRegion(CreateRectRgn(b.Left, b.Top, b.Width + b.Left, b.Height + b.Top), MyBoxes[i].BoundsRect) then
begin
b.top := 50; // set cursor to top=50. // why?
MyBoxes[i].Brush.Color := clRed; // turn that box red
end;
end;
Inside the begin/end you can act on the touching of your cursor to one of the MyBoxes.