请问连接两个动态shape控件的连线如何随控件移动(100分)

  • 主题发起人 石光亮
  • 开始时间

石光亮

Unregistered / Unconfirmed
GUEST, unregistred user!
我通过按钮1生成几个动态控件,用按钮2在控件之间加上连线,在移动控件时想让连线随控件
一起移动。
 
我作过一个动态生成树的东东,每个节点是一个button,中间用线连接起来。
用数组把每个节点的top,left记录下来,每次移动后在重绘。
procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
GetCursorPos(P);
GetCursorPos(origin);
if ssright in shift then
begin
PopUpMenu1.Popup(P.x,P.y);
temp:=TButton(Sender);
Itop:=temp.top;

// showmessage(temp.name);
end;

if ssLeft in Shift then
begin
ReleaseCapture;
getcapture;
(sender as Tbutton).dragmode:=dmManual;
//(sender as Tbutton).dragmode:=dmAutomatic;
TWinControl(Sender).Perform(wm_syscommand,sc_dragmove,0);
Button2Click(Sender);
GetCursorPos(P);
Button2MouseUp(Sender, Button,[ssleft], P.X, P.Y);
// TWinControl(Sender).Perform(wm_syscommand,0,0);
//(sender as Tbutton).dragmode:=dmAutomatic;

end;//动态生成

end;


procedure TForm1.N1Click(Sender: TObject);
var
I:integer;
tempstr:string;

begin
if Itop>400 then
begin
showmessage('底下越界,请调整高度后再新增!');
exit;
end;
Icount:=Icount+1;

lblPick:=TButton.Create(form1);
lblPick.name:='button'+inttostr(Icount);
lblPick.Parent := form1; //注意将其Parent置为容器(一般为Form)
lblPick.Left :=p.x-30;
lblPick.Top := p.y+40;
lblPick.Caption :='症状信息';
lblPick.Hint :=lblPick.Caption;
lblPick.Height:=30;
lblPick.Width:=60;
lblPick.Tag:=Itag;
lblPick.ShowHint :=true;
Form1.memo1.lines.clear;
Form1.memo1.lines.add(lblpick.caption);
//lblPick.OnClick:=Button2Click;
lblPick.OnMouseDown:=Button2MouseDown;
lblPick.OnMouseup:=Button2Mouseup;
lblPick.OnEnter:=Button2Enter;
Itag:=Itag+1;

Form1.bitBtn2.caption:='确定';
showmessage('请在文本框里输入症状信息,然后按"确定"按钮!');
tempstr:=Temp.name+'#'+temp.caption+'##'+inttostr(temp.left)+'###'+inttostr(temp.top)+'####'+lblPick.name+'#####'+lblPick.caption+'######'+inttostr(lblPick.left)+'#######'+inttostr(lblPick.top);
StrList.Add( TempStr);
//showmessage(tempstr);
// showmessage(temp.name);
ARInfo[0,IInfo]:=Temp.name;
ARInfo[1,IInfo]:=temp.caption;
ARInfo[2,IInfo]:=inttostr(temp.left);
ARInfo[3,IInfo]:=inttostr(temp.top);
ARInfo[4,IInfo]:=lblPick.name;
ARInfo[5,IInfo]:=lblPick.caption ;
ARInfo[6,IInfo]:=inttostr(lblPick.left);
ARInfo[7,IInfo]:=inttostr(lblPick.top);
IInfo:=IInfo+1;
//showmessage(inttostr(IInfo));
with image1.canvas do
begin
image1.picture:=nil;
end;
with image1.canvas do
begin
for i:=0 to 100 do
begin
if ((ARInfo[2,I])<>'') and ((ARInfo[3,I]<>'')) then
moveto((strtoint(ARInfo[2,I])+30),(strtoint(ARInfo[3,I]))+20);
if ((ARInfo[6,I])<>'') and ((ARInfo[7,I]<>'')) then
lineto((strtoint(ARInfo[6,I])+30),strtoint(ARInfo[7,I]));
end;
end;



end;

if temp<>button2 then
temp.free;
with image1.canvas do
begin
image1.picture:=nil;
end;
with image1.canvas do
begin
for i:=0 to 100 do
begin
if ((ARInfo[2,I])<>'') and ((ARInfo[3,I]<>'')) then
moveto((strtoint(ARInfo[2,I])+30),(strtoint(ARInfo[3,I]))+20);
if ((ARInfo[6,I])<>'') and ((ARInfo[7,I]<>'')) then

lineto((strtoint(ARInfo[6,I])+30),strtoint(ARInfo[7,I]));
end;
end;
//重绘
 
我刚刚做好了一个类似的东西,你要的话
发email给我
 
me too. charliecy@china.com
 
ok,shiguangliang@263.net
 
zhouyufan,可不可以将你的完整的源码给我一份,我不是很懂.
 
接受答案了.
 
Email是yuguoguang@hotmail.com
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部