控件移动去下个TStretchHandle控件。
控件的Cut,paste 等可用TMemoryStream来实现,
在深度历险有相关的试例的,去看看吧。
以下是我以前一个窗体设计程序的源码,摘下点给你吧:
var
MemStream:TMemoryStream;
function CopyComponent(ParentForm:TForm;CopyComponent:array of TComponent;idx:integer):Boolean;
var
i:integer;
begin
MemStream.Clear;
for i:=0 to Idx-1 do begin
MemStream.WriteComponent(CopyComponent);
end;
Result:=True;
end;
function CutComponent(ParentForm:TForm;CutComponent:array of TComponent;idx:integer):Boolean;
var
i:integer;
begin
MemStream.Clear;
for i:=0 to Idx-1 do begin
MemStream.WriteComponent(CutComponent);
DeleteComponent(ParentForm,CutComponent,True);
end;
Result:=True;
end;
function PasteComponent(ParentForm:TForm):Boolean;
var
NewComp:TComponent;
tmpReader:TReader;
begin
Result:=False;
if MemStream.Size<0 then exit;
MemStream.Position:=0; //置0从头开始
with ParentForm do begin
while MemStream.Position<MemStream.Size do begin
tmpReader:=TReader.Create(MemStream,1024);
try
tmpReader.Parent:=ParentForm;
NewComp:=tmpReader.ReadRootComponent(nil);
InsertComponent(NewComp);
if FindComponent(NewComp.Name)<>nil then begin //如果插入控件己存在则重命名
NewComp.Name:=GetCompNameId(ParentForm,TComponentClass(NewComp.Classtype),True);
//Showmessage('Component Rename:'+GetCompNameId(ParentForm,TComponentClass(NewComp.Classtype),True));
end;
TControl(NewComp).Parent:=ParentForm; //以Component插入必须指明Parent,否则不能显示
//Showmessage('Add Component:'+NewComp.Name);
CreateClassEvent(ParentForm);
Result:=True;
finally
tmpReader.free;
end;
end;
end;
end;
不对之处,还请大家指正。