以前采用如下方法适应800*600与1024*768的分辨率:
  inherited;
  Font.Name := '宋体';
  Font.Size := 9;
    //分辨率问题
  if(Screen.width <> Orignwidth)then
  begin
    FWidth:=Width;
    Scaled:=TRUE;
    Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
    ScaleBy(Screen.Width,Orignwidth); //控件大小调整
    Height:=longint(Height)*longint(Screen.Height) DIV Orignheight;
    Width:=longint(Width)*longint(Screen.Width) DIV Orignwidth;//窗口大小调整
  end;
但现在大多宽屏显示器,如笔记本是1280*800,或19寸宽屏1440*900,以上这个方法就不适用了,请问大家有什么样的方法可以做到,在1024*768下开发的form能自适应1280*800,或1440*900的宽屏显示器呢?

解决方案 »

  1.   

    宽屏好像是DPI和普通显示器不同,不完全是分辨率
      

  2.   

    我一般使用控件的anchors属性来让某个控件占用 扩大或缩小 的长度或宽度
      

  3.   

    分辨率一直是个讨厌的问题,我现在习惯把窗体改成固定大小的,顺便把最大化按钮也去掉,不让用户随意改变大小了。也免去了form和各空间需要动态改变大小尺寸的烦恼
      

  4.   

    我采用了如下的方法,在没有一些特殊控件的情况下可以使用,但是如果出现了Timage或DataSouce或TClentdataSet等这样的控件,就出现了错误,我想用
      if ((Components[i] is TImage)
            or (Components[i] is TDataSource)
              or (Components[i] is TClientDataSet))
                then exit这种方法,但我想不是所有的控制都转换了,应该怎么办呢?
    unit untFixForm;interfaceuses
      Classes, SysUtils, Controls, Forms,
        ExtCtrls, DBClient, DB;type
      TFontedControl = class(TControl)  public
        property Font;
      end;  TFontMapping = record
        SWidth : Integer;
        SHeight: Integer;
        FName: string;
        FSize: Integer;
    end;procedure FixForm(AForm: TForm);
    procedure SetFontMapping;var
      FontMapping : array of TFontMapping;implementationprocedure SetFontMapping;
    begin
      SetLength(FontMapping, 5);// 800 x 600
      FontMapping[0].SWidth := 800;
      FontMapping[0].SHeight := 600;
      FontMapping[0].FName := '宋体';
      FontMapping[0].FSize := 7;// 1024 x 768
      FontMapping[1].SWidth := 1024;
      FontMapping[1].SHeight := 768;
      FontMapping[1].FName := '宋体';
      FontMapping[1].FSize := 9;// 1280 x 1024
      FontMapping[2].SWidth := 1280;
      FontMapping[2].SHeight := 1024;
      FontMapping[2].FName := '宋体';
      FontMapping[2].FSize := 11;// 1280 x 800
      FontMapping[3].SWidth := 1280;
      FontMapping[3].SHeight := 800;
      FontMapping[3].FName := '宋体';
      FontMapping[3].FSize := 11;// 1280 x 800
      FontMapping[4].SWidth := 1440;
      FontMapping[4].SHeight := 900;
      FontMapping[4].FName := '宋体';
      FontMapping[4].FSize := 12;
    end;procedure FixForm(AForm: TForm);
    var
      i, j,x: integer;
      t: TControl;
    begin
      with AForm do
      begin
        i:=0;
        while i<= ComponentCount - 1 do
    //    for i:=0 to ComponentCount - 1 do
        begin
          if ((Components[i] is TImage)
            or (Components[i] is TDataSource)
              or (Components[i] is TClientDataSet))
                then exit
          else
          try
            t := TControl(Components[i]);
            t.left := Trunc(t.left * (Screen.width / 1024));
            t.top := Trunc(t.Top * (Screen.Height / 768));
            t.Width := Trunc(t.Width * (Screen.Width / 1024));
            t.Height := Trunc(t.Height * (Screen.Height / 768));
          except
          end; { try }      i:=i+1;
        end; { for i }    for i:= 0 to Length(FontMapping) - 1 do
        begin
          if (Screen.Width = FontMapping[i].SWidth) and (Screen.Height = FontMapping[i].SHeight) then
          begin
            for j := 0 to ComponentCount - 1 do
            begin
              try
                TFontedControl(Components[j]).Font.Name := FontMapping[i].FName;
                TFontedControl(Components[j]).FONT.Size := FontMapping[i].FSize;
              except
              end; { try }
            end; { for j }
          end; { if }
        end; { for i }
      end; { with }
    end;initialization  SetFontMapping;end.调用时:
    procedure TFrm_Login.FormShow(Sender: TObject);
    begin
      untFixForm.FixForm(Self);
    end;
      

  5.   

    搞个size文件,类似生成不同语言版本的文件,可以生成 1024*768Size,800*600size文件。
    当然也可以只生成默认的 1024*768Size文件,当分辨率不是默认的1024*768时,根据默认的1024*768的size按比例生成其他分辨率的size。
      

  6.   

    根据新的分辨率重画表单及控件。代码:
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      scaled:=true;
      if (screen.width<>orignwidth) then
      begin
        height:=longint(height)*longint(screen.height) div orignheight;
        width:=longint(width)*longint(screen.width) div orignwidth; 
        scaleby(screen.width , orignwidth);
      end;
    end;
      

  7.   

    多已经搜索了两天了,上面的那个unit就是我搜索到并可以使用的方法,但只是在使用一些控件时有错误,不知道是什么原因?
      

  8.   

    请加入QQ高级群:9642802,在群的共享里有个组件"EasySize",组件的作用是控制窗口在不同分辨率下窗口都能成比例的缩放,窗口中的控件也会随窗口的大小变化,自动成比例缩放; 使用方法很简单,拖个控件放到界面上,2句代码搞定。 
    1、FormCreate事件中: 
      FormResizer1.InitializeForm; 
    2、FormResize事件中: 
      FormResizer1.ResizeAll;