How to click and drag to create a new allocation.
Try this, it looks really good. (Our thanks to Marc Hoffmann for this snippet.)
type TUnleashedChart = class(TssResourceAllocationChart); procedure TForm1.RACMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Resource: TssResource; NewAlloc: TssResourceAllocation; StartAt, EndAt, MinimumSpan: TDateTime; Pt: TPoint; begin // don't create allocations if dragging the chart if not (racAllowDragScroll in RAC.Options) then begin Resource := RAC.FindResourceFromY(Y); if Assigned(Resource) then begin StartAt := RAC.XToDateTime(X); // need at least three pixels to allow the // sizing handle to be grabbed EndAt := RAC.XToDateTime(X + 3); MinimumSpan := EncodeTime(0, 15, 0, 0); if EndAt < StartAt + MinimumSpan then EndAt := StartAt + MinimumSpan; if Resource.IsSlotFree(StartAt, EndAt) then begin NewAlloc := Resource.AddSlot(StartAt, EndAt); NewAlloc.Style := rsBlock; Pt := RAC.ClientToScreen(NewAlloc.DisplayRect.BottomRight); Pt.X := Pt.X - 1; Pt.Y := Pt.Y - (NewAlloc.DisplayRect.Bottom - NewAlloc.DisplayRect.Top) div 2; SetCursorPos(Pt.X, Pt.Y); Pt := RAC.ScreenToClient(Pt); // hook into the normal MouseDown handler TUnleashedChart(RAC).MouseDown(Button, Shift, Pt.X, Pt.Y); end; end; end; end;
Copyright © 2000-2010 Simon Armstrong. All Rights Reserved.


