Languages :: Delphi :: Problems writing a component |
|||
| By: stab |
Date: 23/08/2008 22:25:34 |
Points: 20 | Status: Open |
|
Hi all, I'm trying to write a component that, dropped on a form and activated will cause every control on the form to resize together with the form. Looked at the example in article at About Delphi Programming: How to Detect the Start Move/Resize, Move and Stop Move/Resize events of a Form and it worked when used on a form but I can't detect the corresponding windows messages in my component . My component contains a TApplicationEvents object and uses event: OnMessage to enter procedure ResizeAndReposition. The component enters ResizeAndReposition, but it doesn't detect WM_EXITSIZEMOVE that would cause the actual resizing. Can anyone explain way this doesn't work? Code as follows: unit SBResizer; interface uses Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls, ExtCtrls, TypInfo, AppEvnts; type TSBResizer = class(TObject) private { Private declarations } FAOwner : TForm; FApplicationEvent : TApplicationEvents; FEnabled: boolean; FCurrentHeight : integer; FCurrentWidth : integer; FCurrentFontSize : integer; procedure ResizeAndReposition(var Msg: TMsg; var Handled: Boolean); procedure SetEnabled(const Value: boolean); protected { Protected declarations } public { Public declarations } constructor Create(AOwner : TForm); destructor Destroy; override; published { Published declarations } property Enabled : boolean read FEnabled write SetEnabled; end; //procedure Register; implementation uses TwinklePanelTestMain; {procedure Register; begin RegisterComponents('Festina Lente', [TSBResizer]); end;} { TSBResizer } constructor TSBResizer.Create(AOwner: TForm); begin inherited Create; FAOwner := AOwner; FCurrentHeight := FAOwner.Height; FCurrentWidth := FAOwner.Width; FCurrentFontSize := FAOwner.Font.Size; FApplicationEvent := TApplicationEvents.Create(FAOwner); FApplicationEvent.OnMessage := ResizeAndReposition; // FApplicationEvent. end; destructor TSBResizer.Destroy; begin FreeAndNil(FApplicationEvent); inherited; end; procedure TSBResizer.ResizeAndReposition(var Msg: TMsg; var Handled: Boolean); var i : integer; control : TControl; winControl : TWinControl; component : TComponent; fH, fW, fF : double; procedure ResizeComponent(parentComponent : TComponent); var i : integer; component : TComponent; begin i := 0; while i < parentComponent.componentCount do begin component := parentComponent.components; Resizecomponent(component); i := i + 1; end; if parentComponent is TControl then begin TControl(parentComponent).Left := Round(fW * TControl(parentComponent).Left); TControl(parentComponent).Top := Round(fH * TControl(parentComponent).Top); TControl(parentComponent).Height := Round(fH * TControl(parentComponent).Height); TControl(parentComponent).Width := Round(fW * TControl(parentComponent).Width); with parentComponent do begin if GetPropInfo(ClassInfo, 'font') <> nil then begin if abs(fH - 1) > abs(fW - 1) then TEdit(parentComponent).Font.Size := Round(fH * FCurrentFontSize) else TEdit(parentComponent).Font.Size := Round(fW * FCurrentFontSize); end; end; end; end; begin if not FEnabled then Exit; if Msg.message = WM_EXITSIZEMOVE then begin fH := (1.0 - 1.0 + FAOwner.Height) / FCurrentHeight; fW := (1.0 - 1.0 + FAOwner.Width) / FCurrentWidth; if abs(fH - 1) > abs(fW - 1) then FAOwner.Font.Size := Round(fH * FCurrentFontSize) else FAOwner.Font.Size := Round(fW * FCurrentFontSize); i := 0; while i < FAOwner.ComponentCount do begin component := FAOwner.Components; ResizeComponent(component); i := i + 1; end; FCurrentHeight := FAOwner.Height; FCurrentWidth := FAOwner.Width; FCurrentFontSize := FAOwner.Font.Size; Handled := True; end; end; procedure TSBResizer.SetEnabled(const Value: boolean); begin FEnabled := Value; end; end. Regards stab |
|||
| By: VGR | Date: 23/08/2008 23:27:56 | Type : Comment |
|
| Probably TApplicationEvents is either not handling that event or is a third-party component not available in source, right ? Then you could perhaps add this to your TForm descendant (FAOwner) : procedure WMExitSizeMove(var Message: TMessage) ; message WM_EXITSIZEMOVE; and call TSBResizer.ResizeAndReposition() HTH |
|||
|
Do register to be able to answer |
|||
| Add This Article To: | |||
| |
|
|
|
| |
|
|
|









