窗体最大化后,其中的所有控件按比列放大如何操作呢??
先谢谢了!

解决方案 »

  1.   

    在OnResize  事件里面写代码啊!
    判断当前窗口缩放的比例罗,然后遍历窗体上的控件 width和height 都乘上这个比例!
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Panel1: TPanel;
        Button1: TButton;
        Edit1: TEdit;
        procedure FormResize(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        OldWinWidth : integer;
        OldWinHeight : integer;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormResize(Sender: TObject);
    var
      WRate,HRate : double;
      i : integer;
    begin
      WRate := Form1.Width / OldWinWidth;
      HRate := Form1.Height / OldWinHeight;
      for i := 0 to  Form1.ControlCount - 1 do
      begin
        if Form1.Controls[i] is TPanel then
        begin
          (Form1.Controls[i] as TPanel).Width :=trunc( (Form1.Controls[i] as TPanel).Width*WRate);
          (Form1.Controls[i] as TPanel).Height :=trunc(  (Form1.Controls[i] as TPanel).Height*HRate);
        end  
        else if Form1.Controls[i] is TButton then
        begin
          (Form1.Controls[i] as TButton).Width :=trunc(  (Form1.Controls[i] as TButton).Width*WRate);
          (Form1.Controls[i] as TButton).Height :=trunc(  (Form1.Controls[i] as TButton).Height*HRate);
        end
        else if Form1.Controls[i] is TEdit then
        begin
          (Form1.Controls[i] as TEdit).Width :=trunc(  (Form1.Controls[i] as TEdit).Width*WRate);
          (Form1.Controls[i] as TEdit).Height :=trunc(  (Form1.Controls[i] as TEdit).Height*HRate);
        end 
        //......
        //其他类型的控件。
        //......
      end;
      OldWinWidth :=Width;
      OldWinHeight :=Height;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      OldWinWidth := Width;
      OldWinHeight := Height;
    end;end.