c++builder How to prohibit dragging legends
Posted: Mon Jul 24, 2023 1:32 am
How to prohibit dragging legends?
Steema Software - Customer Support Forums
http://teechart.com/support/
Sorry but it should not be draggable by default.
TAnnotationTool
doesn't support dragging. However, the TRectangleTool
does.TAnnotationTool
and adding a TSelectorTool
to add dragging support to it, you could just use a TRectangleTool
.TSelectorTool
not to detect the Legend. So, instead of using the TSelectorTool
, I'd implement the TAnnotationTool
dragging myself.Code: Select all
#include <VclTee.Chart.hpp>
#include <VclTee.Series.hpp>
#include <VclTee.TeeTools.hpp>
Code: Select all
private: // User declarations
TChart* Chart1;
TAnnotationTool* Annotation;
TPoint* annotationOffset;
bool annotationDragging;
void __fastcall ChartMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall ChartMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall ChartMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
Code: Select all
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Chart1 = new TChart(this);
Chart1->Parent = this;
Chart1->Align = alClient;
Chart1->Color = clWhite;
Chart1->Gradient->Visible = False;
Chart1->Walls->Back->Color = clWhite;
Chart1->Walls->Back->Gradient->Visible = False;
Chart1->View3D = False;
for (int i=0; i < 2; i++) {
TFastLineSeries* fastLine = new TFastLineSeries(this);
Chart1->AddSeries(fastLine);
fastLine->FillSampleValues();
}
Annotation = new TAnnotationTool(this);
Chart1->Tools->Add(Annotation);
Annotation->Left = 100;
Annotation->Top = 100;
Annotation->Text = "Annotation tool";
Chart1->OnMouseDown = ChartMouseDown;
Chart1->OnMouseMove = ChartMouseMove;
Chart1->OnMouseUp = ChartMouseUp;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (Annotation->Clicked(X,Y))
{
annotationDragging = true;
annotationOffset = new TPoint(X-Annotation->Left,Y-Annotation->Top);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if ((!annotationDragging) and (Annotation->Clicked(X,Y)))
{
Chart1->Cursor = crHandPoint;
Chart1->CancelMouse = true;
}
if (annotationDragging)
{
Annotation->Left = X-annotationOffset->X;
Annotation->Top = Y-annotationOffset->Y;
Chart1->CancelMouse = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChartMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if (annotationDragging)
{
Chart1->Zoom->Active = false;
Chart1->CancelMouse = true;
}
annotationDragging = false;
}
Chart1->Legend
. Ie:Code: Select all
void __fastcall TForm1::ChartMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
//...
Chart1->Legend->Color = clRed;
}
Legend
is in a given position with the Clicked
function. Ie:Code: Select all
if (Chart1->Legend->Clicked(X, Y) > -1)
{
Chart1->Legend->Color = clRed;
}
else
{
Chart1->Legend->Color = clWhite;
}
Sorry, in what example?wrote: ↑Tue Aug 08, 2023 1:22 amHow to prevent the legend from being dragged during the chartmousemove event, as shown in the following example???