怎样缩放无标题的窗体(106分)

  • 主题发起人 主题发起人 devexpress
  • 开始时间 开始时间
D

devexpress

Unregistered / Unconfirmed
GUEST, unregistred user!
如题

public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams); override;
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

procedure TMainForm.WMNCHitTest(var Message: TWMNCHitTest);
begin
inherited;
Message.Result := HTCAPTION;
end;

procedure TMainForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style xor ws_caption xor ws_popup;
{或者Params.Style := WS_THICKFRAME or WS_POPUP or WS_BORDER;}
end;

通过上面的方法,可以实现, 但还是有一个边框, 
 
Delphi之未经证实的葵花宝典version 2.7

实现可缩放的无标题窗体
怎样可以不要Form的标题栏和边界但可以保留改变Form的大小的功能:
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
private
procedure WmNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}

procedure TForm1.WmNCHitTest(var Msg: TWMNCHitTest);
const v=10; //border width
var p:TPoint;
begin
p:=Point(Msg.XPos,Msg.YPos);
p:=ScreenToClient(p);
if PtInRect(Rect(0,0,v,v),p) then
Msg.Result:=HTTOPLEFT
else if PtInRect(Rect(Width-v,Height-v,Width,Height),p) then
Msg.Result:=HTBOTTOMRIGHT
else if PtInRect(Rect(Width-v,0,Width,v),p) then
Msg.Result:=HTTOPRIGHT
else if PtInRect(Rect(0,Height-v,v,Height),p) then
Msg.Result:=HTBOTTOMLEFT
else if PtInRect(Rect(v,0,Width-v,v),p) then
Msg.Result:=HTTOP
else if PtInRect(Rect(0,v,v,Height-v),p) then
Msg.Result:=HTLEFT
else if PtInRect(Rect(Width-v,v,Width,Height-v),p) then
Msg.Result:=HTRIGHT
else if PtInRect(Rect(v,Height-v,Width-v,Height),p) then
Msg.Result:=HTBOTTOM;
Inherited;
end;
end.
 
楼上的这段代码,我试过不起作用
 
我用了最简单,又最笨的方法实现了。 

public
procedure CreateParams(var Params: TCreateParams); override;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
//Params.Style := Params.Style xor ws_caption xor ws_popup;
Params.Style := WS_THICKFRAME or WS_POPUP or WS_BORDER;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
s:integer;
begin
s:=-3; //这样子就可以了。
self.BorderWidth:=s;
end;
 
后退
顶部