1.采用控件数组。 procedure TForm1.FormCreate(Sender: TObject); var iControlCount :integer; begin for iControlCount :=0 to Self.ControlCount-1 do begin if Self.Controls[iControlCount] is TCheckBox then begin (Self.Controls[iControlCount] as TCheckBox).Caption :='MyCheckBox'+IntToStr(iControlCount); //这里用你自已的命名方式 (Self.Controls[iControlCount] as TCheckBox).OnClick :=RadioButton1Click; ....[8D]//这里写其它属性 end; end; end;2.重载控件的Paint方法 如Timage控件利用Componentstate属性来确定一个控件是处于运行状态还是设计状态,以此来决定是否要载控件周围画上虚框: Precedure TImage.Paint; begin if csDesigning in CompohnentState then begin //只在设计时画虚框 with inherited Canvas do begin pen.Style:=psDash; Brush.Style:=bsClear; Rectangel(0,0,Width,Height);//画上虚框 end; end; ....//接着绘制控件的图象部分 end;
procedure TForm1.FormCreate(Sender: TObject);
var
iControlCount :integer;
begin
for iControlCount :=0 to Self.ControlCount-1 do
begin
if Self.Controls[iControlCount] is TCheckBox then
begin
(Self.Controls[iControlCount] as TCheckBox).Caption :='MyCheckBox'+IntToStr(iControlCount); //这里用你自已的命名方式
(Self.Controls[iControlCount] as TCheckBox).OnClick :=RadioButton1Click;
....[8D]//这里写其它属性
end;
end;
end;2.重载控件的Paint方法
如Timage控件利用Componentstate属性来确定一个控件是处于运行状态还是设计状态,以此来决定是否要载控件周围画上虚框:
Precedure TImage.Paint;
begin
if csDesigning in CompohnentState then
begin //只在设计时画虚框
with inherited Canvas do
begin
pen.Style:=psDash;
Brush.Style:=bsClear;
Rectangel(0,0,Width,Height);//画上虚框
end;
end;
....//接着绘制控件的图象部分
end;
我说的是:如何象Delphi一样,可以选择多个控件,当用鼠标拖动其中一个时,其他选中的控件也同时随之移动。
如何实现??!谢谢各位!!