对不起,boss要我五一期间加班,有气没处发!
说话过火!请原谅!不打不相识吗?交个朋友吧,留个e-mail吧?
e-mail:zhenghui8101@21cn.com
问题已经自己解决了!还差几个点没画!
有两种解决办法!
一种在窗体上动态产生与控件大小一样的tshape控件,拖动tshape控件;放下tshape,改变
控件的位置
第二种画画布:付上代码
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure Button1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
procedure Button1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
procedure FormMouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Draw:Boolean=false;
oldx1,oldy1,oldx2,oldy2:integer;
CanvaLeft,CanvaTop,CanvaWidth,CanvaHeight:integer;
//旧画布
newLeft,newTop,newRight,newBotton:integer;
//新画布坐标
mousex,mousey:integer;//窗体上鼠标的坐标
implementation
{$R *.DFM}
procedure TForm1.Button1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
Draw:=true;
flag:=true;
// oldx:=mouse.CursorPos.X;
// oldy:=mouse.CursorPos.y;
mousex:=button1.left+x;
mousey:=button1.top+y;
with Canvas do
begin
Pen.Color := clGray;
Pen.Mode := pmXor;
Pen.Width := 2;
Brush.Style := bsClear;
Rectangle(button1.Left, button1.Top, button1.left+button1.width,button1.Top+button1.Height);
end;
CanvaLeft:=button1.Left;
CanvaTop:=button1.Top;
CanvaWidth:=button1.left+button1.width;
CanvaHeight:=button1.Top+button1.Height;
label2.caption:='button1.Width '+inttostr(button1.Width)+#13+#10+
'button1.height '+inttostr(button1.Height)+#13+#10;
//记录鼠标数据与画布的各个点的距离
oldx1:=x;
oldy1:=y;
oldx2:=button1.width-x;
oldy2:=button1.height-y;
label1.Caption:='x='+inttostr(oldx1)+#13+#10+
'y='+inttostr(oldy1)+#13+#10+
'oldx2:=button1.width-x='+inttostr(oldx2)+#13+#10+
'oldy2:=height-y='+inttostr(oldy2)+#13+#10;
end;
procedure TForm1.Button1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
mousex:=button1.left+x;
mousey:=button1.top+y;
form1.Caption:=inttostr(mousex)+#13+#10+
inttostr(mousey);
if draw then
begin
//新画布的坐标
newLeft:=mousex-Oldx1;
newTop:=mousey-oldy1;
newRight:=oldx2+mousex;
newBotton:=oldy2+mousey;
label3.Caption:='新画布坐标'+'newLeft: '+inttostr(newLeft)+#13+#10+
'newTop: '+inttostr(newTop)+#13+#10+
'newRight: '+inttostr(newRight)+#13+#10+
'newBotton: '+inttostr(newBotton)+#13+#10;
with Canvas do
begin
Pen.Color := clGray;
Pen.Mode := pmXor;
Pen.Width := 2;
Brush.Style := bsClear;
Rectangle(CanvaLeft, CanvaTop,CanvaWidth,CanvaHeight);
Rectangle(newLeft,newTop,newRight,newBotton);
end;
//旧画布坐标
CanvaLeft:=newLeft;
CanvaTop:=newTop;
CanvaWidth:=newRight;
CanvaHeight:=newBotton;
label4.Caption:='旧画布坐标: '+'CanvaLeft: '+inttostr(CanvaLeft)+#13+#10+
'CanvaTop: '+inttostr(CanvaTop)+#13+#10+
'CanvaWidth: '+inttostr(CanvaWidth)+#13+#10+
'CanvaHeight: '+inttostr(CanvaHeight)+#13+#10;
end;
end;
procedure TForm1.Button1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
button1.Left:=CanvaLeft;
button1.top:=CanvaTop;
with Canvas do
begin
Pen.Color := clGray;
Pen.Mode := pmXor;
Pen.Width := 2;
Brush.Style := bsClear;
Rectangle(button1.Left, button1.Top, button1.left+button1.width,button1.Top+button1.Height);
end;
draw:=false;
end;
procedure TForm1.FormMouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
mousex:=x;
mousey:=y;
form1.Caption:=inttostr(x)+' '+inttostr
;
end;
end.