unit1.pas

来自「《Delphi实用程序100例》配套书源码盘」· PAS 代码 · 共 65 行

PAS
65
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowSize;
    procedure RestrictSize(var msg: TMessage); message WM_GETMINMAXINFO;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ShowSize;
begin
   Label1.Caption := IntToStr(Width)+'X'+IntToStr(Height);
end;

procedure TForm1.RestrictSize(var Msg: TMessage);
var
   p: PMinMaxInfo;
begin
// The lParam contains a pointer on a structure of type TMinMaxInfo
   p := PMinMaxInfo(Msg.lParam);
// This represents the size of the Window when Maximized
   p.ptMaxSize.x := 320;
   p.ptMaxSize.y := 240;
// This represents the position of the Window when Maximized
   p.ptMaxPosition.x := 10;
   p.ptMaxPosition.y := 10;
// This represents the minimum size of the Window
   p.ptMinTrackSize.x := 320;
   p.ptMinTrackSize.y := 240;
// This represents the maximum size of the Window
   p.ptMaxTrackSize.x := 400;
   p.ptMaxTrackSize.y := 320;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  ShowSize;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  ShowSize;
end;

end.
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?