-
[Delphi]폼 크기에 맞게 자동으로 컴포넌트 크기 조절하기Delphi/예제소스 2022. 1. 27. 18:05
위에 분꺼 Delphi로 변경한거
PS. 그냥 Delphi 말고 C++builder로 할까.... c++이 더 좋은데....delphi 헷갈려...
Caption크기는 변경안됨.
unit Unit4; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm4 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; procedure FormCreate(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; {FromScale} TDefaultControl = record Width : integer; Height : integer; Left : integer; Top : integer; end; PDefCtrl = ^TDefaultControl; var Form4: TForm4; implementation {$R *.dfm} var DefaultWidth : integer; DefaultHeight : integer; procedure TForm4.FormCreate(Sender: TObject); var winCtrl : TWinControl; defCtrl : PDefCtrl; i : integer; begin i := 0; while (i < Form4.ComponentCount) do begin New(defCtrl); winCtrl := TWinControl(Form4.Components[i]); defCtrl.Width := winCtrl.Width; defCtrl.Height := winCtrl.Height; defCtrl.Left := winCtrl.Left; defCtrl.Top := winCtrl.Top; winCtrl.Tag := integer(defCtrl); Inc(i); end; DefaultWidth := Width; DefaultHeight := Height; end; procedure TForm4.FormDestroy(Sender: TObject); var winCtrl : TWinControl; defCtrl : PDefCtrl; i : integer; begin i := 0; while i < Form4.ComponentCount do begin winCtrl := TWinControl(Form4.Components[i]); defCtrl := PDefCtrl(winCtrl.Tag); Dispose(defCtrl); // winCtrl.Tag := NULL; Inc(i); end; end; procedure TForm4.FormResize(Sender: TObject); var winCtrl : TWinControl; defCtrl : PDefCtrl; i : integer; iW, iH, iL, iT : integer; fZoomX, fZoomY : double; begin i := 0; fZoomX := double(Width)/double(DefaultWidth); fZoomY := double(Height)/double(DefaultHeight); while (i < Form4.ComponentCount) do begin winCtrl := TWinControl(Form4.Components[i]); defCtrl := PDefCtrl(winCtrl.Tag); iW := Trunc(defCtrl.Width * fZoomX); iH := Trunc(defCtrl.Height * fZoomY); iL := Trunc(defCtrl.Left * fZoomX); iT := Trunc(defCtrl.Top * fZoomY); Inc(i); if iW < 1 then Continue; if iH < 1 then Continue; if iL < 1 then Continue; if iT < 1 then Continue; winCtrl.Width := iW; winCtrl.Height := iH; winCtrl.Left := iL; winCtrl.Top := iT; end; end; end.
https://m.blog.naver.com/50after/221787616902
Panel 방식
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, System.Math; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Edit1: TEdit; Edit2: TEdit; Panel1: TPanel; procedure FormResize(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormResize(Sender: TObject); var h, w : double; p : integer; begin w := ClientWidth / Panel1.Width; h := ClientWidth / Panel1.Height; p := Round( min( w, h) * 100.0); Panel1.ScaleBy(p, 100); end; end.
728x90'Delphi > 예제소스' 카테고리의 다른 글
[Delphi] 해상도 ui조절 (0) 2022.01.03 댓글