Delphi 在窗体任意指定矩形区拖动窗体

其实只是利用一个隐藏的控件来制定矩形区域,可以使Button、Panel、Memo等,总之看不见它,然后在窗体OnMouseDown函数中添加SendMessage(Handle, WM_SYSCOMMAND, 61457, 0);来移动窗体,具体代码如下:

新建工程,加一个Panel控件,Visible属性设为False,调整大小,完成后鼠标在该控件矩形内可以拖动窗体,而该位置可以添加Image等,就能实现伪标题栏效果:

//开始

unit Unit1;

interface

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

type
TForm1 = class(TForm)
    Panel1: TPanel;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
private
    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ptInRect(Rect(Panel1.Left,Panel1.Top,Panel1.Width+Panel1.Left,Panel1.Height+Panel1.Top),Point(X,Y)) then
begin
ReleaseCapture;
SendMessage(Handle, WM_SYSCOMMAND, 61457, 0);
end;
end;

end.

转自:http://hi.baidu.com/dykvsuffotbhtxr/item/48091a4a5b926bf7dc0f6cf6

posted @ 2013-02-07 17:23  stma  阅读(541)  评论(0)    收藏  举报