I am adding a band to a chart as soon as the user clicks on the chart--and I want to start resizing the band as soon as it is added. Can that be done?
Thanks
Ed Dressel
Adding a TColorBandTool, resizing immediately
-
- Newbie
- Posts: 14
- Joined: Mon Jan 18, 2016 12:00 am
Re: Adding a TColorBandTool, resizing immediately
Hello Ed,
Yes, you can use the mouse events to do so.
I'm not sure how do you want to determine what TColorLineTool (StartLine/EndLine) should be dragged (note dragging one of the two TColorLineTools in the TColorBandTool is a TColorBandTool resizing) when you just created the tool.
Here you have an example that creates the TColorBandTool and starts dragging it at OnMouseDown event:
Yes, you can use the mouse events to do so.
I'm not sure how do you want to determine what TColorLineTool (StartLine/EndLine) should be dragged (note dragging one of the two TColorLineTools in the TColorBandTool is a TColorBandTool resizing) when you just created the tool.
Here you have an example that creates the TColorBandTool and starts dragging it at OnMouseDown event:
Code: Select all
uses Series, TeeTools;
type TMyColorBandTool=class(TColorBandTool)
private
Dragging : Boolean;
Old : Double;
end;
var myColorBand: TMyColorBandTool;
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
Chart1.AddSeries(TBarSeries).FillSampleValues();
end;
procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if not Assigned(myColorBand) then
begin
myColorBand:=Chart1.Tools.Add(TMyColorBandTool) as TMyColorBandTool;
with myColorBand do
begin
Axis:=Chart1.Axes.Bottom;
StartValue:=2;
EndValue:=4;
if not ParentChart.CancelMouse then
begin
Dragging:=True;
if Axis.Horizontal then
Old:=Axis.CalcPosPoint(X)-StartValue
else
Old:=Axis.CalcPosPoint(Y)-StartValue;
ParentChart.CancelMouse:=True;
end;
end;
end;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var tmpValue,
tmpStartValue,
tmpDiff : Double;
begin
if Assigned(myColorBand) and myColorBand.Dragging then
begin
with myColorBand do
begin
tmpDiff:=EndValue-StartValue;
if Axis.Horizontal then
tmpValue:=Axis.CalcPosPoint(X)-Old
else
tmpValue:=Axis.CalcPosPoint(Y)-Old;
if NoLimitDrag then
tmpStartValue:=tmpValue
else
tmpStartValue:=StartLine.LimitValue(tmpValue);
tmpValue:=EndLine.LimitValue(tmpStartValue+tmpDiff);
if (not NoLimitDrag) and (tmpValue<(tmpStartValue+tmpDiff)) then
StartValue:=tmpValue-tmpDiff
else
StartValue:=tmpStartValue;
EndValue:=StartValue+tmpDiff;
end;
end;
end;
procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Assigned(myColorBand) then
myColorBand.Dragging:=False;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |