delphi禁止用鼠标拖动窗口的大小

2018-10-31

//方法一, 同 BorderStyle := bsSingle;
unit Unit1;

interface

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

type
TForm1 = class(TForm)
protected
procedure CreateParams(var Params: TCreateParams); override;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style xor WS_THICKFRAME;
end;

end.
--------------------------------------------------------------------------------


//方法二, 笨办法:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

var w,h: Integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
w := ClientWidth;
h := ClientHeight;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
ClientWidth := w;
ClientHeight := h;
end;

end.
--------------------------------------------------------------------------------


//方法三: 使用 OnCanResize 事件
unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
var Resize: Boolean);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
Resize := False;
end;

end.
阅读116