本文整理自网络,侵删。
unit Unit1;
interface
usesWinapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,Vcl.Controls, Vcl.Forms, Vcl.Dialogs,Typinfo, Vcl.StdCtrls;
typeTForm1 = class(TForm)Button1: TButton;procedure FormCreate(Sender: TObject);procedure Button1Click(Sender: TObject);private
{ Private declarations }public{ Public declarations }end;
varForm1: TForm1;
implementation
{$R *.dfm}function PropertyExists(const AObject: TObject; const APropName: string): Boolean;varPropInfo: PPropInfo;beginPropInfo := GetPropInfo(AObject.ClassInfo, APropName);Result := Assigned(PropInfo);end;
function GetObjectProperty(const AObject: TObject;const APropName: string): TObject;varPropInfo: PPropInfo;beginResult := nil;PropInfo := GetPropInfo(AObject.ClassInfo, APropName);if Assigned(PropInfo) and(PropInfo^.PropType^.Kind = tkClass) thenResult := GetObjectProp(AObject, PropInfo);end;
procedure FitDeviceResolution(Sender: TForm);constOriWidth = 1440;OriHeight = 900;vari: Integer;j: Integer;LocAnchors: array of TAnchors;LocAlign: array of TAlign;LocList: TList;LocFontSize: Integer;LocFont: TFont;LocCmp: TComponent;ScrResolutionRateH, ScrResolutionRateW,LocFontRate: Double;beginScrResolutionRateH := Screen.Height / OriHeight;ScrResolutionRateW := Screen.Width / OriWidth;if Abs(ScrResolutionRateH - 1) < Abs(ScrResolutionRateW - 1) thenLocFontRate := ScrResolutionRateHelseLocFontRate := ScrResolutionRateW;LocList := TList.Create;trytryif (screen.width <> OriWidth) or (screen.Height <> OriHeight) thenbeginSender.Scaled := False;for i := Sender.ComponentCount - 1 downto 0 dobeginLocCmp := Sender.Components[i];if LocCmp is TControl thenLocList.Add(LocCmp);if PropertyExists(LocCmp, 'FONT') thenbeginLocFont := 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 dowith TControl(LocList.Items[i]) dobeginLocAnchors[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 dobeginwith TControl(LocList.Items[i]) dobeginTop := Round(Top * ScrResolutionRateH);Left := Round(Left * ScrResolutionRateW);Height := Round(height * ScrResolutionRateH);Width := Round(width * ScrResolutionRateW);end;end;for i := 0 to LocList.Count - 1 doTControl(LocList.Items[i]).Align := LocAlign[i];for i := 0 to LocList.Count - 1 doTControl(LocList.Items[i]).Anchors := LocAnchors[i];end;exceptMessageDlg(LocCMP.Name, mtInformation, [mbOK], 0);end;finallyLocList.Free;end;end;procedure TForm1.Button1Click(Sender: TObject);beginFitDeviceResolution(Self);end;
procedure TForm1.FormCreate(Sender: TObject);beginFitDeviceResolution(Self);end;
end.
相关阅读 >>
Delphi 在 listbox 中放置一��可�� item 的 tedit �m件
Delphi webbrowser载入自定义html内容并显示
Delphi 分解时间 �cdecodedate、decodetime … decodedatetime …
Delphi adoconnection1 连接excel 读取数据
更多相关阅读请进入《Delphi》频道 >>