Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit ResizeControlEditor;
- interface
- procedure Register;
- implementation
- uses
- Controls,
- DesignEditors,
- DesignIntf,
- Math,
- Types;
- type
- TControlAutoSizeEditor = class(TDefaultEditor)
- public
- procedure ExecuteVerb(Index: Integer); override;
- function GetVerb(Index: Integer): string; override;
- function GetVerbCount: Integer; override;
- end;
- procedure Register;
- begin
- RegisterComponentEditor(TWinControl, TControlAutoSizeEditor);
- end;
- procedure AdjustSizeToContent(AControl: TWinControl);
- const
- MARGIN = 3;
- var
- i: Integer;
- LWidth, LHeight: Integer;
- LBounds: TRect;
- begin
- LWidth := 0;
- LHeight := 0;
- for i := 0 to AControl.ControlCount - 1 do
- begin
- LBounds := AControl.Controls[i].BoundsRect;
- LWidth := Max(LWidth, LBounds.Right + MARGIN);
- LHeight := Max(LHeight, LBounds.Bottom + MARGIN);
- end;
- AControl.ClientWidth := LWidth;
- AControl.ClientHeight := LHeight;
- end;
- { TControlAutoSizeEditor }
- procedure TControlAutoSizeEditor.ExecuteVerb(Index: Integer);
- begin
- case Index of
- 0: AdjustSizeToContent(Component as TWinControl);
- end;
- end;
- function TControlAutoSizeEditor.GetVerb(Index: Integer): string;
- begin
- case Index of
- 0: Result := 'Resize control to fit content';
- end;
- end;
- function TControlAutoSizeEditor.GetVerbCount: Integer;
- begin
- if csAcceptsControls in (Component as TWinControl).ControlStyle then
- Result := 1
- else
- Result := 0;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement