如何让一个BorderStyle是BsNone的窗体可以让用户调节窗体大小,即让窗体同时又是Sizeable的?

解决方案 »

  1.   

    响应WM_NCHITTEST消息,在消息的结果中返回HTTOP,HTBOTTOM等
    详见WinApi帮助-WM_NCHITTESTunit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure WMNCHITTEST(var msg: TMessage); message WM_NCHITTEST;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      Close;
    end;procedure TForm1.WMNCHITTEST(var msg: TMessage);
    begin
      msg.Result := HTBOTTOM;
    end;end.
      

  2.   

    在onmousedown中写如下代码
    begin
      判断鼠标的位置
      ReleaseCapture;
      PreForm(WM_SYSCOMMAND, Para, 0);
    end;Para = $F001..$F008
    自己试试看吧
      

  3.   

    在onmousedown中写如下代码
    begin
      判断鼠标的位置
      ReleaseCapture;
      PreForm(WM_SYSCOMMAND, Para, 0);
    end;Para = $F001..$F008
    自己试试看吧
      

  4.   

    还可以这样
    在onmousedown中写如下代码
    begin
      判断鼠标的位置
      ReleaseCapture;
      PreForm(WM_SYSCOMMAND, Para, 0);
    end;Para = $F001..$F008
    自己试试看吧
      

  5.   

    procedure CreateParams(var Params: TCreateParams); override;
    procedure TFormMain.CreateParams(var Params: TCreateParams);
    //change the form style
    //2003.02.13
    begin
      inherited CreateParams(Params);
      with Params do
      begin
        Style:=(Style or WS_POPUP) xor (ws_dlgframe);
        ExStyle:=ws_ex_clientedge;
      end;
    end;
      

  6.   

    protected
      procedure CreateParams(var Params: TCreateParams); override;procedure TfrmMain.CreateParams(var Params: TCreateParams);
    begin
      inherited;
      Params.Style := WS_POPUP or WS_BORDER or WS_SIZEBOX;
    end;
      

  7.   

    procedure TForm.HitTest(var Msg: TWmNcHitTest);
    var
      pt: TPoint;
    begin
      pt := Point(Msg.xPos, Msg.yPos);
      pt := ScreenToClient(pt);
      if (pt.x < 5) and (pt.y < 5) then
        Msg.Result := htTopLeft
      else if (pt.x > Width - 5) and (pt.y < 5) then
        Msg.Result := htTopRight
      else if (pt.x > Width - 5) and (pt.y > Height - 5) then
        Msg.Result := htBottomRight
      else if (pt.x < 5) and (pt.y > Height - 5) then
        Msg.Result := htBottomLeft
      else if (pt.x < 5) then
        Msg.Result := htLeft
      else if (pt.y < 5) then
        Msg.Result := htTop
      else if (pt.x > Width - 5) then
        Msg.Result := htRight
      else if (pt.y > Height - 5) then
        Msg.Result := htBottom
      else
        inherited;
    end;