拖动没有标题栏的窗体
http://delphi.about.com/od/windowsshellapi/a/dragnocaption.htm
步骤如下:
1、在窗体的private声明中写下:
procedure WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest;
2、在implement声明:
步骤如下:
1、在窗体的private声明中写下:
procedure WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest;
2、在implement声明:
procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest) ;
begin
inherited;
if Msg.Result = htClient then Msg.Result := htCaption;//欺骗windows
end;
以上代码,只有鼠标是在窗体上移动拖拉时才有效。如果窗体上有panel,而且是alClient,那么以上代码则无效。
需要加入以下代码:
procedure TForm1.Panel1MouseDown
(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer) ;
begin
ReleaseCapture;
SendMessage(Form1.Handle, WM_SYSCOMMAND, 61458, 0) ;
end;
(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer) ;
begin
ReleaseCapture;
SendMessage(Form1.Handle, WM_SYSCOMMAND, 61458, 0) ;
end;
还有其他变通情况:
if Msg.Result = htClose then Msg.Result := htNowhere;
if Msg.Result = htCaption then Msg.Result := htClient;// 不给移动窗体