怎样让Panel在窗体上拖动和拉伸

来源:互联网 发布:linux 查看网络配置 编辑:程序博客网 时间:2024/04/29 00:52
type TMyButton = class(TButton) protected procedure WMNCHitTest(var Msg:TWMNCHitTest);message WM_NCHITTEST; end; implementation //CM_DESIGNHITTEST procedure TMyButton.WMNCHitTest(var Msg:TWMNCHitTest); begin //if ((Msg.Pos.y <(Top + 3)) and (Msg.Pos.y > (Top + 3))) then Msg.Result :=HTCAPTION; //if ((Msg.Pos.y <(Top + 3)) and (Msg.Pos.y > (Top + Height + 3)) and // (Msg.Pos.x <(Left + Width + 3))) then // Msg.Result :=HTLEFT; //if (Msg.Pos.y>(Top+3)) and (Msg.Pos.y>(Top+Height-3)) then begin // if (Msg.Pos.x<(Left-3)) then // Msg.Result:=HTLEFT // else if (Msg.Pos.x>(Left+Width-3)) then // Msg.Result:=HTRIGHT; //end; end;  unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Button1Click(Sender: TObject); private procedure ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer); { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure Tform1.ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer); var SC_MANIPULATE: Word; begin //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //光标在控件的最左侧********************************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (X<=Precision) and (Y>Precision) and (Y=Control.Width-Precision) and (Y>Precision) and (YPrecision) and (X=Control.Width-Precision) and (Y<=Precision) then begin SC_MANIPULATE := $F005; Control.Cursor := crSizeNESW ; end //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //光标在控件的最下侧********************************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ else if (X>Precision) and (X=Control.Height-Precision) then begin SC_MANIPULATE := $F006; Control.Cursor := crSizeNS; end //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //光标在控件的左下角********************************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ else if (X<=Precision) and (Y>=Control.Height-Precision) then begin SC_MANIPULATE := $F007; Control.Cursor := crSizeNESW; end //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //光标在控件的右下角********************************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ else if (X>=Control.Width-Precision) and (Y>=Control.Height-Precision) then begin SC_MANIPULATE := $F008; Control.Cursor := crSizeNWSE; end //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //光标在控件的客户区(移动整个控件)****************************************** //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ else //if (X>5) and (Y>5) and (X<Control.Width-5) and (Y<Control.Height-5) then begin SC_MANIPULATE := $F009; Control.Cursor := crDefault; //SizeAll; { end else begin SC_MANIPULATE := $F000; Control.Cursor := crSizeAll; //Default; } end; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if Shift=[ssLeft] then begin ReleaseCapture; Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0); end; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin label1.Caption := IntToStr(X) + '/' + IntToStr(Y); ManipulateControl((Sender as Tform), Shift, X, Y, 10); end; procedure TForm1.Button1Click(Sender: TObject); begin close; end; end.