unit Elastic; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,Forms, Dialogs, ExtCtrls; type TElasticPanel = class( TPanel )privateFHorz, FVert: boolean;nOldWidth, nOldHeight: integer;bResized: boolean;protectedprocedure WMSize( var message: TWMSize ); message WM_SIZE;publicnCount: integer;constructor Create( AOwner: TComponent ); override;publishedproperty ElasticHorizontal: boolean read FHorz write FHorz defaultTRUE; property ElasticVertical: boolean read FVert write FVert defaultTRUE; end; procedure Register; implementation constructor TElasticPanel.Create( AOwner: TComponent ); begin inherited Create( AOwner );FHorz := TRUE;FVert := TRUE;nOldWidth := Width;nOldHeight := Height;bResized := FALSE;end; procedure TElasticPanel.WMSize( var message: TWMSize ); var bResize: boolean;xRatio: real;i: integer;ctl: TWinControl;begin Inc( nCount );if Align = alNone thenbResize := TRUEelsebResize := bResized;if not ( csDesigning in ComponentState ) and bResize thenbeginif FHorz thenbeginxRatio := Width / nOldWidth;for i := 0 to ControlCount - 1 dobeginctl := TWinControl( Controls[i] );ctl.Left := Round( ctl.Left * xRatio );ctl.Width := Round( ctl.Width * xRatio );end;end;if FVert thenbeginxRatio := Height / nOldHeight;for i := 0 to ControlCount - 1 dobeginctl := TWinControl( Controls[i] );ctl.Top := Round( ctl.Top * xRatio );ctl.Height := Round( ctl.Height * xRatio );end;end;endelsebeginnOldWidth := Width;nOldHeight := Height;end;bResized := TRUE;nOldWidth := Width;nOldHeight := Height;end; procedure Register; begin RegisterComponents('Additional', [TElasticPanel]);end; end. |