DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: laidabin
今日帖子: 4
在线用户: 31
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 hlc_alf ★☆☆☆☆ -
普通会员
2003/6/4 8:36:40
标题:
再次紧急求教! 浏览:2220
加入我的收藏
楼主: 如果我想让各个子窗体的大小为主窗体的0.8倍,且子窗体中的各个控件(如edit,combobox,panel)随着窗体的大小按比例动态调整,请问如何实现!最好举个例子。
----------------------------------------------
-
作者:
男 boy (阿門) ★☆☆☆☆ -
盒子活跃会员
2003/6/4 9:50:57
1楼:     OW,OH,OP: Longint;
    aName: array of String;
    aLeft,aTop,aWidth,aHeight,aFWidth,aFHeight: array of Longint;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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;

end.

----------------------------------------------
Delphi開發◆伺服器架設◆免安裝APACHE,PHP,CGI Perl, MYSQL ★
作者:
男 hlc_alf ( ) ★☆☆☆☆ -
普通会员
2003/6/4 15:00:37
2楼: 我试一下,如果不行或那里不明白再向您老人家请教!
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行99.60938毫秒 RSS