在设计期我们就可以发现,如果改变ToolBar的宽度,ToolButton的位置会有相应的变化。 利用这一点,可以模拟在程序中动态地调整ToolBar本身的宽度,强迫它重新安排ToolButton。 测试程序——procedure TForm1.Button1Click(Sender: TObject); begin with ToolButton2 do Visible := not Visible; with ToolBar1 do begin Width := Width + ButtonWidth;//如果不行把ButtonWidth换成个较大的数试试 Width := Width - ButtonWidth;//恢复ToolBar原来的宽度 end; end;
有PANEL+BITBTN控件
利用这一点,可以模拟在程序中动态地调整ToolBar本身的宽度,强迫它重新安排ToolButton。
测试程序——procedure TForm1.Button1Click(Sender: TObject);
begin
with ToolButton2 do Visible := not Visible;
with ToolBar1 do begin
Width := Width + ButtonWidth;//如果不行把ButtonWidth换成个较大的数试试
Width := Width - ButtonWidth;//恢复ToolBar原来的宽度
end;
end;
当ToolBar.ShowCaptions为True时,每一个ToolButton的实际宽度由它们当中Caption最长的一个决定,所以如果你隐藏了那个Caption最长的Button以后,行数肯定要减少。因此建议你在Caption上想想办法,比如在某个短Caption两端都加空格,以保证所有的Caption长度相同。