unit Unit1;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,Typinfo, Vcl.StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private { Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm}
function PropertyExists(const AObject: TObject; const APropName: string): Boolean;
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(AObject.ClassInfo, APropName);
Result := Assigned(PropInfo);
end; function GetObjectProperty(
const AObject: TObject;
const APropName: string
): TObject;
var
PropInfo: PPropInfo;
begin
Result := nil;
PropInfo := GetPropInfo(AObject.ClassInfo, APropName);
if Assigned(PropInfo) and
(PropInfo^.PropType^.Kind = tkClass) then
Result := GetObjectProp(AObject, PropInfo);
end; procedure FitDeviceResolution(Sender: TForm);
const
OriWidth = 1440;
OriHeight = 900;
var
i: Integer;
j: Integer;
LocAnchors: array of TAnchors;
LocAlign: array of TAlign;
LocList: TList;
LocFontSize: Integer;
LocFont: TFont;
LocCmp: TComponent;
ScrResolutionRateH, ScrResolutionRateW,LocFontRate: Double;
begin
ScrResolutionRateH := Screen.Height / OriHeight;
ScrResolutionRateW := Screen.Width / OriWidth;
if Abs(ScrResolutionRateH - 1) < Abs(ScrResolutionRateW - 1) then
LocFontRate := ScrResolutionRateH
else
LocFontRate := ScrResolutionRateW;
LocList := TList.Create;
try
try
if (screen.width <> OriWidth) or (screen.Height <> OriHeight) then
begin
Sender.Scaled := False;
for i := Sender.ComponentCount - 1 downto 0 do
begin
LocCmp := Sender.Components[i];
if LocCmp is TControl then
LocList.Add(LocCmp);
if PropertyExists(LocCmp, 'FONT') then
begin
LocFont := TFont(GetObjectProperty(LocCmp, 'FONT'));
LocFontSize := Round(LocFontRate * LocFont.Size);
LocFont.Size := LocFontSize;
end;
end;
SetLength(LocAnchors, LocList.Count);
SetLength(LocAlign, LocList.Count);
for i := 0 to LocList.Count - 1 do
with TControl(LocList.Items[i]) do
begin
LocAnchors[i] := Anchors;
LocAlign[i] := Align;
Align := alNone;
Anchors := [akLeft, akTop];
end;
Sender.Top := Round(Sender.Top * ScrResolutionRateH);
Sender.Left := Round(Sender.Left * ScrResolutionRateW);
Sender.Height := Round(Sender.Height * ScrResolutionRateH);
Sender.Width := Round(Sender.Width * ScrResolutionRateW);
Sender.Font.size := Round(LocFontRate * Sender.Font.size);
for i := 0 to LocList.Count - 1 do
begin
with TControl(LocList.Items[i]) do
begin
Top := Round(Top * ScrResolutionRateH);
Left := Round(Left * ScrResolutionRateW);
Height := Round(height * ScrResolutionRateH);
Width := Round(width * ScrResolutionRateW);
end;
end;
for i := 0 to LocList.Count - 1 do
TControl(LocList.Items[i]).Align := LocAlign[i];
for i := 0 to LocList.Count - 1 do
TControl(LocList.Items[i]).Anchors := LocAnchors[i];
end;
except
MessageDlg(LocCMP.Name, mtInformation, [mbOK], 0);
end;
finally
LocList.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FitDeviceResolution(Self);
end; procedure TForm1.FormCreate(Sender: TObject);
begin
FitDeviceResolution(Self);
end; end.

Delphi 让窗体自适应屏幕显示的更多相关文章

  1. Delphi:窗体自适应屏幕分辨率的改进

    在窗体依据屏幕分辨率自适应调整尺度方面,昨天的工作可以说是一个突破点.昨天的工作找到了长期以来我的原有方案的问题所在,这是非常关键的.但是昨天晚上的解决方案并不完美,今天的这个才是比较完美的解决版. ...

  2. Delphi 实现窗体自适应调整尺寸以适应不同屏幕分辩率的显示问题

    给你一段代码,网上转的:unit uMyClassHelpers;//实现窗体自适应调整尺寸以适应不同屏幕分辩率的显示问题.//        陈小斌,2012年3月5日 interface Uses ...

  3. Delphi:窗体自适应屏幕分辨率(根据预设值的比例改变)

    delphi 程序适应屏幕分辨率,先在表单单元的Interface部分定义两个常量, 表示设计时的屏幕的宽度和高度(以像素为单位). 在表单的Create事件中先判断 当前分辨率是否与设计分辨率相同, ...

  4. delphi 窗体自适应屏幕分辨率

    delphi 窗体自适应屏幕分辨率 这是个困惑我很长时间的问题,到今天终于得到解决了. 话说Delphi有个很强的窗体设计器,这一点让VC粉丝垂涎三尺而不可得.但是,Delphi里设计的窗体并没有自动 ...

  5. WPF之路四:窗体自适应

    下面我来举个例子说明如何用Grid或DockPanel来实现自适应窗体. 让我们新建一个WPF工程,完成后我们打开对应的XAML文件,可以看到VS已经自动添加了<Grid></Gri ...

  6. WinForm窗体自适应分辨率

    我们自己编写程序的界面,会遇到各种屏幕分辨率,只有自适应才能显的美观.实际上,做到这点也很简单,就是首先记录窗体和它上面控件的初始位置和大小,当窗体改变比例时,其控件的位置和大小也按此比例变化即可.因 ...

  7. delphi实现窗体闪烁功能

    delphi实现窗体闪烁功能 以前做窗口闪动时都没有考虑到让任务栏上的按钮闪动的问题, 现在一个客户需要任务栏按钮闪动,发现以前使用的flashwindow不能达到要求了, 查找了一下,找到flash ...

  8. Delphi中窗体的事件

    Delphi中窗体的事件 Form窗体可以响应各种各样的时间,在Object Inspector的Events页面中罗列了一大堆,如下图: 下面将要列出一些常用的事件. 1.OnActivate 当窗 ...

  9. delphi 程序窗体及控件自适应分辨率(通过ComponentCount遍历改变字体大小以及上下左右)

    unit untFixForm; interface uses Classes, SysUtils, Controls, Forms; type TFontedControl = class(TCon ...

  10. C# 正则表达式测试工具与分享窗体自适应类

    放假刚回来,自己打算写一个正则表达式的测试工具,因为上次在网上用的一个在线正则表示测试工具就 没有很好的服务自己的,所以才有了现在的想法,想写一个C#开发者用的正则表达式测试工具!期间由于最大化时控件 ...

随机推荐

  1. 【狂神说Java】Java零基础学习笔记-Java基础

    [狂神说Java]Java零基础学习笔记-Java基础 Java基础01:注释 平时我们编写代码,在代码量比较少的时候,我们还可以看懂自己写的,但是当项目结构一旦复杂起来,我们就需要用到注释了. 注释 ...

  2. linux网桥(Linux Bridge)的一些个人记录

    目录 1. Linux Bridge简述 2. 网桥创建 创建 配置持久化 在Debian/Ubuntu系统上: 在CentOS/RHEL系统上: 启用和验证 3. 关于linux网桥不转发ip帧的问 ...

  3. LCR 164. 破解闯关密码

    破解闯关密码 闯关游戏需要破解一组密码,闯关组给出的有关密码的线索是: 一个拥有密码所有元素的非负整数数组 password 密码是 password 中所有元素拼接后得到的最小的一个数 请编写一个程 ...

  4. ids4-startup

    https://stackoverflow.com/questions/28418360/jwt-json-web-token-audience-aud-versus-client-id-whats- ...

  5. UWP 系统通知测试

    code: using System; using System.Collections.Generic; using System.IO; using System.Linq; using Syst ...

  6. ClickHouse-3引擎

    引擎 数据库引擎 index 表引擎 数据库引擎 数据库引擎允许您处理数据表. 默认情况下,ClickHouse使用Atomic数据库引擎.它提供了可配置的table engines和SQL dial ...

  7. excel表格里面数据统计有几个(相同的算1个)

    例如:1 2 3 4 5 6 7 1 2 3 统计出来的结果 是 7个! 相同的算1个. 假设数据在A1:A10区域内,在B1单元格中显示结果,则在B1单元格中输入公式: =SUMPRODUCT(1/ ...

  8. YUV 格式

    1. YUV比例 分三种:YUV44,YUV422,YUV420 2. YUV排布 分三种:YUV planar,YUV Semi-Plannar,YUV packed 以YUV422 8*4 为例 ...

  9. CP56Time2A时间转换

    * CP56Time2A时间格式 该时标格式使用7个字节来表示时间信息,上图的表中体现为--从最左侧8所在的行开始,到下面56所在的行,共7行.每一行表示一个字节,每行从右向左依次是该字节的第一位(最 ...

  10. Keepalived基本原理

    本文分享自天翼云开发者社区<Keepalived基本原理>,作者:Ujnrfc Keepalived简介 Keepalived是Linux下一个轻量级别的高可用解决方案.高可用:广义来讲, ...