怎样可以用鼠标移动form1上的panel?(50分)

  • 主题发起人 主题发起人 gravel
  • 开始时间 开始时间
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
procedure Panel1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure Panel1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Panel1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure FormMouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Panel1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
var
P:TPoint;
begin
if Panel1.Tag=0 then
Exit;
P.x:=X;
P.y:=Y;
with Panel1do
begin
P:=Form1.ScreenToClient(ClientToScreen(P));
Left:=P.x-X+1;
Top:=P.y-Y+1;
Repaint;
end;
end;

procedure TForm1.Panel1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Panel1.Tag:=1;
end;

procedure TForm1.Panel1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Panel1.Tag:=0;
end;

procedure TForm1.FormMouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Panel1.Tag:=0;
end;

end.
 
非常简单的搞定:
procedure TForm1.Panel1MouseDown(Sender: TObject;
Button: TMouseButton;Shift: TShiftState;
X, Y: Integer);
begin
if Button <> mbRight then
begin

ReleaseCapture;
Form1.Perform(WM_SysCommand, $f017, 0);
end;
end;
 
kai,题意是移动Panel
gravel,在Panel1的OnMouseDown中加如下代码即可搞定:
if Button=mbLeft then
begin
POSTMESSAGE(panel1.handle,WM_LBUTTONUP,0,0);
POSTMESSAGE(panel1.handle,274,61458,0);
end;
 
如果只想移动,设置一下Dock的属性不就行了吗.
 
为何不在已答问题中找找?
 
找个控件不就很好吗?我有一组这佯的控件,不知道是不是InfoPower里的
不记得了,很酲!
 
多人接受答案了。
 
后退
顶部