I need to know when the user has released the mouse button when dragging or resizing the Gantt. You suggested using the OnDragBar and OnResizeBar. That will not work. I need to know the moment the action has stopped and I can only conceive that a Mouse Up event would work.
I need to round the X value and pass that back to the Gantt. (snap).
I have found the OnMouse up property in the Chart class and several others. I can not find where the event is trapped. Since a mouse click is taking place, I know the event is fired. How can I access this?
We have the full source.
Thanks
Trapping a Mouse Up Event when using the Gantt tool
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Gainco,
In that case you can try doing something like this:
In that case you can try doing something like this:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1.FillSampleValues();
Dragged:=false;
Resized:=false;
end;
procedure TForm1.ChartTool1DragBar(Sender: TGanttTool; GanttBar: Integer);
begin
Dragged:=true;
end;
procedure TForm1.ChartTool1ResizeBar(Sender: TGanttTool; GanttBar: Integer;
BarPart: TGanttToolBarPart);
begin
Resized:=true;
end;
procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (Dragged or Resized) then
begin
Chart1.Title.Text[0]:=FloatToStr(Chart1.Axes.Bottom.CalcPosPoint(X));
end;
Dragged:=false;
Resized:=false;
end;
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
We got it working.
Similar to your way but we beat you to it.
Brillant minds think alike
Here is out test code for anyone still struggling.
=======================================
procedure TForm2.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ActiveGantt.Gantt.StartValues[ActiveGanttBar] := Int(ActiveGantt.Gantt.StartValues[ActiveGanttBar]);
ActiveGantt.Gantt.EndValues[ActiveGanttBar] := Int(ActiveGantt.Gantt.EndValues[ActiveGanttBar]);
Edit1.text := FloatToStr(ActiveGantt.Gantt.StartValues[ActiveGanttBar]);
Edit2.text :=FloatToStr(ActiveGantt.Gantt.EndValues[ActiveGanttBar]);
GanttChanged := False;
end;
procedure TForm2.ChartTool1DragBar(Sender: TGanttTool; GanttBar: Integer);
begin
GanttChanged := true;
ActiveGantt := Sender;
ActiveGanttBar := GanttBar;
Edit1.text :=FloatToStr(Sender.Gantt.StartValues[GanttBar]);
Edit2.text :=FloatToStr(Sender.Gantt.EndValues[GanttBar]);
Edit3.text :=IntToStr(GanttBar);
end;
procedure TForm2.ChartTool1ResizeBar(Sender: TGanttTool; GanttBar: Integer;
BarPart: TGanttToolBarPart);
var
StartVal, EndVal : Double;
begin
StartVal:= Sender.Gantt.StartValues[GanttBar];
EndVal := Sender.Gantt.EndValues[GanttBar];
Edit1.text :=FloatToStr(Sender.Gantt.StartValues[GanttBar]);
Edit2.text :=FloatToStr(Sender.Gantt.EndValues[GanttBar]);
public
{ Public declarations }
Property ActiveGantt : TGanttTool read fActiveGantt write fActiveGantt;
Property ActiveGanttBar : Integer read fActiveGanttBar write fActiveGanttBar;
Property GanttChanged : Boolean read fGanttChanged write fGanttChanged;
end;
GanttChanged := true;
ActiveGanttBar := GanttBar;
// (pbStart,pbAll,pbEnd);
Case BarPart of
pbStart : Edit6.text := 'Start';
pbAll : Edit6.text := 'All';
pbEnd : Edit6.text := 'End';
End;
ActiveGantt := Sender;
end;
Brillant minds think alike
Here is out test code for anyone still struggling.
=======================================
procedure TForm2.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ActiveGantt.Gantt.StartValues[ActiveGanttBar] := Int(ActiveGantt.Gantt.StartValues[ActiveGanttBar]);
ActiveGantt.Gantt.EndValues[ActiveGanttBar] := Int(ActiveGantt.Gantt.EndValues[ActiveGanttBar]);
Edit1.text := FloatToStr(ActiveGantt.Gantt.StartValues[ActiveGanttBar]);
Edit2.text :=FloatToStr(ActiveGantt.Gantt.EndValues[ActiveGanttBar]);
GanttChanged := False;
end;
procedure TForm2.ChartTool1DragBar(Sender: TGanttTool; GanttBar: Integer);
begin
GanttChanged := true;
ActiveGantt := Sender;
ActiveGanttBar := GanttBar;
Edit1.text :=FloatToStr(Sender.Gantt.StartValues[GanttBar]);
Edit2.text :=FloatToStr(Sender.Gantt.EndValues[GanttBar]);
Edit3.text :=IntToStr(GanttBar);
end;
procedure TForm2.ChartTool1ResizeBar(Sender: TGanttTool; GanttBar: Integer;
BarPart: TGanttToolBarPart);
var
StartVal, EndVal : Double;
begin
StartVal:= Sender.Gantt.StartValues[GanttBar];
EndVal := Sender.Gantt.EndValues[GanttBar];
Edit1.text :=FloatToStr(Sender.Gantt.StartValues[GanttBar]);
Edit2.text :=FloatToStr(Sender.Gantt.EndValues[GanttBar]);
public
{ Public declarations }
Property ActiveGantt : TGanttTool read fActiveGantt write fActiveGantt;
Property ActiveGanttBar : Integer read fActiveGanttBar write fActiveGanttBar;
Property GanttChanged : Boolean read fGanttChanged write fGanttChanged;
end;
GanttChanged := true;
ActiveGanttBar := GanttBar;
// (pbStart,pbAll,pbEnd);
Case BarPart of
pbStart : Edit6.text := 'Start';
pbAll : Edit6.text := 'All';
pbEnd : Edit6.text := 'End';
End;
ActiveGantt := Sender;
end;