Delphi自动适应屏幕大小

Delphi自动适应屏幕大小
//自动适应屏幕大小:作者:海宏软件,周承昊。
function autoFitScreen640_480(oContainer:TWinControl):Boolean;
const defaultScreenWidth=800;   defaultScreenHeight=600;
var i,j:integer;      n:double;   v:Variant;
    cmt:TComponent;   obj:TObject;   
    ppi:pPropInfo;    fnt:TFont;
begin
    result:=false;
    //分辨率自适应
    if (screen.width < defaultScreenWidth) then with oContainer do begin
        height:=longint(height) * longint(screen.height) DIV defaultScreenHeight;
        width := longint(width) * longint(screen.width) DIV defaultScreenWidth;
        scaleBy(screen.width, defaultScreenWidth);
        //缩放字体,属性设置部分参考:http://topic.csdn.net/t/20030423/20/1699661.html
        n:=(screen.Width / defaultScreenWidth);
        for i:=ComponentCount-1 downto 0 do begin
          cmt:=components[i];
          with cmt do begin
            ppi:=GetPropInfo(cmt, 'font');          //ClassInfo取对象的属性值
            //有此属性    PropInfo^.PropType^.Kind   =   tkClass
            if (ppi<>nil) and (ppi^.PropType^.Kind=tkClass) then begin
              obj:=GetObjectProp(cmt, 'font');      //获取对象的属性对象
              if (not assigned(obj)) then continue;
              fnt:=obj as TFont;                    //取得字体
              //计算出新的字体
              j:=trunc( (fnt.size * screen.Width) / defaultScreenWidth);
              if j<7 then j:=9 else if j<8 then j:=9;
              //设置字体font.size := j;
              fnt.Size:=j;
              SetObjectProp(cmt, 'font', fnt);
            end;
          end;
        end;
    end;
end;

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值