大家帮忙看一下代码!!!(20分)

  • 主题发起人 主题发起人 zhenghui
  • 开始时间 开始时间
Z

zhenghui

Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码用于其它控件可实现设计时拖动,用于edit时该如何实现设计时的拖动,
或给出更好的代码程序实现delphi设计时的控件拖动
procedure TForm1.Edit1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
flag:=true;
oldx:=mouse.CursorPos.X;
oldy:=mouse.CursorPos.y;
end;

procedure TForm1.Edit1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
if flag then
begin
edit1.Left:=edit1.Left-oldx+mouse.CursorPos.X;
edit1.Top:=edit1.Top+y-oldy+mouse.CursorPos.y;
oldx:=mouse.CursorPos.X;
oldy:=mouse.CursorPos.y;
end;
end;

procedure TForm1.Edit1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
flag:=false;
end;
 
procedure TForm1.Edit1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
releasecapture;
edit1.Perform(wm_syscommand,$f012 ,0);
end;
这个问题好像讨论过很多次了吧。。
 
这么简单的问题!我就不会提问了!
wm_syscommand是将控件发出窗体的消息,对没有句柄的控件无效!如label,
image等!
而且上面的指令将光标放在edit上时,聚焦到edit框内并可输入文本,
我要实现的是delphi的设计效果,你可以在窗体上放上Label,
image,buttton等控件拖动一下看看delphi的效果,
不要看了一些编程技巧,乱套,有些东西不是万能的,请调试完,再发表你的
言论!
 
faint,
“以下代码用于其它控件可实现设计时拖动,用于edit时该如何实现设计时的拖动,
或给出更好的代码程序实现delphi设计时的控件拖动”
难道你的要求我没达到?
EDIT不能动了?你有要求与设计环境一样的拖运效果?
技巧当然不是万能的,不过能用技巧实现的,我干嘛要去避开它?
气愤。。。不再关注。。。。
 
请看清楚我要的设计时的拖动效果,并不只是拖动;
插干你的嘴巴!大富翁不是骂人的地方
 
1、“可实现设计时拖动”???
  我还真是看错了,不过设计阶段不是本来就能拖动???,我现在不明白你的需求了。。
2、FAINT
  如果你认为FAINT是骂人的话,那么。。。我只能再次FAINT
 
对不起,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(y);
end;

end.
 

Similar threads

后退
顶部