Recent

Author Topic: How to draw a rectangle, and then delete it  (Read 14322 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 832
    • Blog personal
How to draw a rectangle, and then delete it
« on: April 05, 2011, 09:09:39 pm »
Hello, I use this code to draw a rectangule, over a canvas

Code: Pascal  [Select][+][-]
  1.   Canvas.Brush.Style := bsClear;
  2.   Canvas.Pen.Mode := pmCopy;
  3.   Canvas.Rectangle(100,100,200,200);
  4.  

When I want to delete it, I use:
Code: Pascal  [Select][+][-]
  1.    Canvas.Brush.Style := bsClear;
  2.   Canvas.Pen.Mode := pmNotCopy;
  3.   Canvas.Rectangle(100,100,200,200);        
  4.  

But This code, makes a rectangle with a white border.

Any help?

/BlueIcaro

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: How to draw a rectangle, and then delete it
« Reply #1 on: April 05, 2011, 09:20:57 pm »
Because clWhite is the inverse color of clBlack.

In order to restore the background correctly, you need to save it previously.

To save and draw:
Code: [Select]
var
  r, r2 :trect;
begin
  r.Top := 100;
  r.Left := 100;
  r.Right := 200;
  r.Bottom := 200;
  r2.Top := 0;
  r2.Left := 0;
  r2.Right := 100;
  r2.Bottom := 100;
  Image2.Canvas.Copyrect(r2, canvas, r);
  Canvas.Brush.Color := clBlack;
  Canvas.Pen.Color := clBlack;
  Canvas.Rectangle(100,100,200,200);
end;                     

To restore:
Code: [Select]
var
  r, r2 :trect;
begin
  r.Top := 100;
  r.Left := 100;
  r.Right := 200;
  r.Bottom := 200;
  r2.Top := 0;
  r2.Left := 0;
  r2.Right := 100;
  r2.Bottom := 100;
  Canvas.Copyrect(r, image2.canvas, r2);
end;       
« Last Edit: April 05, 2011, 10:08:13 pm by typo »

BlueIcaro

  • Hero Member
  • *****
  • Posts: 832
    • Blog personal
Re: How to draw a rectangle, and then delete it
« Reply #2 on: April 05, 2011, 10:27:17 pm »
Thnak you!!, it's works!!!

/BlueIcaro

 

TinyPortal © 2005-2018