一toolbar 上有若干toolbutton, 其中有若干个tbsSeparator. 我想实现Group的效果.
就是一个toolbutton按下,其他的都起来.
因为tbsSeparator的存在, 设置Group属性是不行的.要求,不用第三方控件. 代码应该是一个方法, 所有toolbutton调用这个方法,传递一个参数(toolbutton的Name.).如果有更好的想法也行. 尽量要求简单.

解决方案 »

  1.   

    想到一个方法,但希望有更好的procedure TRegionForm.ControlTBControlMap(tbName: String);
    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;
      

  2.   

    使用toolbutton(sender).name来判断,可以在一过程中同时响应多个按钮的事件处理
      

  3.   

    楼上的意思就是把tbName 换成 TToolBtton(Sender).Name.
     还有没有更简单的处理方式
      

  4.   

    我的是意思不必在每一个ToolButton中都调用这个过程 的实现办法
      

  5.   

    procedure TRegionForm.ControlTBControlMap(tbName: String);
    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;