procedure TForm1.FormCreate(Sender: TObject); var V: Variant; I,J: Integer; begin OW := TForm(Sender).Width; OH := TForm(Sender).Height; OP := TForm(Sender).PixelsPerInch; J := 0; // 記錄屬於 TControl 的元件總數 for I := 0 to ComponentCount-1 do if (Components[I] is TControl) then Inc(J); if J > 0 then begin SetLength(aName,J); SetLength(aLeft,J); SetLength(aTop,J); SetLength(aWidth,J); SetLength(aHeight,J); SetLength(aFWidth,J); SetLength(aFHeight,J); for I := Low(aName) to High(aName) do begin aName[I] := '; aLeft[I] := 0; aTop[I] := 0; aWidth[I] := 0; aHeight[I] := 0; aFWidth[I] := 0; aFHeight[I] := 0; end; end; J := -1; for I := 0 to ComponentCount-1 do begin if not (Components[I] is TControl) then Continue; Inc(J); aName[J] := TControl(Components[I]).Name; aLeft[J] := TControl(Components[I]).Left; aTop[J] := TControl(Components[I]).Top; aWidth[J] := TControl(Components[I]).Width; aHeight[J] := TControl(Components[I]).Height; // 檢查是否有 font property V := GetPropValue (Components[I], 'Font'); if not VarIsNull(V) then begin aFWidth[J] := TEdit(Components[I]).Font.Size; aFHeight[J] := TEdit(Components[I]).Font.Height; end; end; end;
procedure TForm1.FormResize(Sender: TObject); var V: Variant; I,J: Integer; L,W,H,T,FS,FH: Longint; NW,NH,NP: Longint; begin // TStatusBar 的 Panel 要特別處理 NW := TForm(Sender).Width; NH := TForm(Sender).Height; NP := TForm(Sender).PixelsPerInch; J := -1; for I := 0 to ComponentCount-1 do begin if not (Components[I] is TControl) then Continue; Inc(J); L := aLeft[J]; W := aWidth[J]; H := aHeight[J]; T := aTop[J]; if OW <> 0 then TControl(Components[I]).Left := Longint(L*NW div OW); if OH <> 0 then TControl(Components[I]).Top := Longint(T*NH div OH); if OW <> 0 then TControl(Components[I]).Width := Longint(W*NW div OW); if OH <> 0 then TControl(Components[I]).Height := Longint(H*NH div OH); // 檢查是否有 font property V := GetPropValue (Components[I], 'Font'); if not VarIsNull(V) then begin FS := aFWidth[J]; FH := aFHeight[J]; if (OP <> 0) and (OW <> 0) then begin TEdit(Components[I]).Font.Size := Longint((FS * NP div OP) * NW div OW); TEdit(Components[I]).Font.Height := Longint((FH * NP div OP) * NH div OH); end; end; end; end;