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

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.    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值