TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
-
Chartist
- Newbie
- Posts: 60
- Joined: Wed Sep 18, 2013 12:00 am
Post
by Chartist » Mon Apr 14, 2014 10:50 am
Hi,
I added several rectangles at runtime by the code below.
How can I address one rectangle at runtime to delete it?
To do it with
" ........ .DeleteSelected;"
would be great.
Thanks,
Cheryll
===========================
adding code:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
begin
Text:='Rectangle Tool 1';
AutoSize:=true;
Shape.Transparency:=0;
Left:=100;
Top:=75;
OnClick:=RectClick;
end;
end;
procedure TForm1.RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
begin
with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
begin
Text:=Sender.Text + ' (twin)';
AutoSize:=Sender.AutoSize;
Shape.Transparency:=Sender.Shape.Transparency;
Top:=Sender.Top+Sender.Height;
Left:=Sender.Left;
OnClick:=RectClick;
end;
end;
end;
Cheryll
-
Yeray
- Site Admin
- Posts: 9612
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Apr 15, 2014 10:38 am
Hi Cheryll,
You could have a global variable (TRectangleTool) storing the selected tool. Then you could use event to change from a tool for another and to remove the selected one. In this example I change the rectangle color pen to highlight the selected tool, I use the same RectClick event to change the tool selected and I use the KeyDown event to remove the selected tool if Supr key is pressed.
Code: Select all
var selectedRect: TRectangleTool;
procedure TForm1.FormCreate(Sender: TObject);
begin
with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
begin
Text:='Rectangle Tool 1';
AutoSize:=true;
Shape.Transparency:=0;
Left:=100;
Top:=75;
OnClick:=RectClick;
end;
end;
procedure TForm1.RectClick(Sender:TAnnotationTool; Button:TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button=mbRight then
begin
with Chart1.Tools.Add(TRectangleTool) as TRectangleTool do
begin
Text:=Sender.Text + ' (twin)';
AutoSize:=Sender.AutoSize;
Shape.Transparency:=Sender.Shape.Transparency;
Top:=Sender.Top+Sender.Height;
Left:=Sender.Left;
OnClick:=RectClick;
end;
end
else if Button=mbLeft then
begin
if Assigned(selectedRect) then
selectedRect.Shape.Pen.Color:=clBlack;
selectedRect:=Sender as TRectangleTool;
selectedRect.Shape.Pen.Color:=clRed;
end;
end;
procedure TForm1.Chart1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_DELETE then
if selectedRect<>nil then
begin
Chart1.Tools.Remove(selectedRect);
Chart1.Repaint;
end;
end;
-
Chartist
- Newbie
- Posts: 60
- Joined: Wed Sep 18, 2013 12:00 am
Post
by Chartist » Mon Apr 28, 2014 11:17 am
Thank you so much!
This works fine.
Cheryll
Cheryll