Reputation: 4239
I am trying to make an analog clock, wherein I would like to make my 'seconds' Line Invisible when the Seconds Changes. I have tried to set the Pen mode to pmNotCopy
but it only gives Inverse of Pen Color. What Property must be set in this Form1.Canvas.Pen.Mode:=<Blank>
so that My Line Disappears?
Any other Ideas are also appreciated.
Thanks
Upvotes: 2
Views: 1462
Reputation: 125669
You were close. You need to use pmXOR
.
Try this:
Create a new Delphi VCL Forms application. Drop a TButton on the bottom of the form (Button1). Add the code below to the Button1Click event.
Run the application. Click the button, and three parallel lines will be drawn across the top. Click the button again, and the three lines will disappear.
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
Canvas.Pen.Mode := pmXor;
Canvas.Pen.Color := clGreen;
for i := 1 to 3 do
begin
Canvas.MoveTo(50, i * 20);
Canvas.LineTo(Width - 50, i * 20);
end;
end;
All drawing should normally be done in the OnPaint event; I'm intentionally drawing in the Button1Click event for demonstration reasons only.
Just as a note: You should never use Form1
inside an event handler for that form. Referencing the Form1
variable prevents you from creating more than one instance of the form. Use Self
instead, and that will automatically refer to the instance the code is running in.
Upvotes: 2
Reputation: 807
I don't know anything about delphi but just some out if the box thinking: couldn't you change the color of your line to the background color, making it 'invisible'
Upvotes: 2
Reputation: 108948
Modern computers are very fast. If I were you, I'd definitely draw the entire clock from scratch every second. Problem solved. In addition, if you need anti-aliasing, then a simple pen mode trick will never work.
(If you are not using a remote desktop, you might want to employ double-buffering.)
Upvotes: 9