Page 1 of 1

Trapping a Mouse Up Event when using the Gantt tool

Posted: Mon Oct 01, 2007 2:48 pm
by 9345379
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

Posted: Mon Oct 01, 2007 2:59 pm
by narcis
Hi Gainco,

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;

We got it working.

Posted: Mon Oct 01, 2007 3:43 pm
by 9345379
Similar to your way but we beat you to it.

Brillant minds think alike :D

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;