一toolbar 上有若干toolbutton, 其中有若干个tbsSeparator. 我想实现Group的效果.
就是一个toolbutton按下,其他的都起来.
因为tbsSeparator的存在, 设置Group属性是不行的.要求,不用第三方控件. 代码应该是一个方法, 所有toolbutton调用这个方法,传递一个参数(toolbutton的Name.).如果有更好的想法也行. 尽量要求简单.
就是一个toolbutton按下,其他的都起来.
因为tbsSeparator的存在, 设置Group属性是不行的.要求,不用第三方控件. 代码应该是一个方法, 所有toolbutton调用这个方法,传递一个参数(toolbutton的Name.).如果有更好的想法也行. 尽量要求简单.
var
i: Integer;
begin
for i:=0 to tbControlMap.ComponentCount-1 do begin
if Components[i].Name <> tbName then
TToolButton(Components[i]).Down := False
else TToolButton(Components[i]).Down := True;
end;
end;
还有没有更简单的处理方式
var
i: Integer;
begin
for i:=0 to tbControlMap.ComponentCount-1 do begin
if Components[i].Name <> tbName then
TToolButton(Components[i]).Down := False
else TToolButton(Components[i]).Down := True;
end;
end;
这段代码很有问题tbControlMap 是一个ToolBar ,我的本意是遍历这个ToolBar上的所有控件,可是tbControlMap.ComponentCount=0现在改为这样,那效率就太差了吧!!!procedure TRegionForm.ControlTB(tb: TToolBar; Sender: TObject);
var
i: Integer;
begin
for i:=0 to ComponentCount-1 do
if Components[i] is TToolButton then begin
if Components[i].Name <> TToolButton(Sender).Name then
TToolButton(Components[i]).Down := False
else TToolButton(Components[i]).Down := True;
end;
end;