ich hab das mal in die SizeControl-Komponente von Angus Johnson integriert (da ich dieses Feature auch im
DFM-Editor haben wollte):
Delphi-Quellcode:
TTargetObj = class
private
....
procedure AlignToGrid(Ctrl: TControl; ProposedBoundsRect: TRect; GridSize: integer);
...
TSizeCtrl = class(TComponent)
private
...
fSnapToGrid: boolean;
...
published
...
property SnapToGrid: boolean read fSnapToGrid write fSnapToGrid;
...
//changed global function AlignToGrid to method of TTargetObj
procedure TTargetObj.AlignToGrid(Ctrl: TControl; ProposedBoundsRect: TRect; GridSize: integer);
begin
//AlignToGrid() assumes 'Control' is assigned.
if (GridSize > 1) and (FSizeCtrl.SnapToGrid) then
begin
...
procedure TTargetObj.MoveFocus(dx,dy: integer);
begin
fFocusRect := fStartRec;
if fSizeCtrl.SnapToGrid then
begin
dx:=dx div fsizectrl.GridSize * fsizectrl.GridSize;
dy:=dy div fsizectrl.GridSize * fsizectrl.GridSize;
end;
offsetRect(fFocusRect, dx,dy);
end;
//------------------------------------------------------------------------------
procedure TTargetObj.SizeFocus(dx,dy: integer; BtnPos: TBtnPos);
begin
fFocusRect := fStartRec;
if fSizeCtrl.SnapToGrid then
begin
dx:=dx div fsizectrl.GridSize * fsizectrl.GridSize;
dy:=dy div fsizectrl.GridSize * fsizectrl.GridSize;
end;
...
für die faulen unter euch ist die komplette Komponente im Anhang
Gruß Frank