可以的。我用的是D4你用的是那个版本的?
我把原代码给你。
dfm File
____________________________________________________________________
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object btnShowCaption: TButton
Left = 232
Top = 160
Width = 75
Height = 25
Caption = 'ShowCaption'
ParentShowHint = False
ShowHint = True
TabOrder = 0
OnClick = btnShowCaptionClick
end
object btnChangeSize: TButton
Left = 88
Top = 56
Width = 75
Height = 25
Caption = 'ChangeSize'
TabOrder = 1
OnClick = btnChangeSizeClick
end
object ToolBar1: TToolBar
Left = 0
Top = 0
Width = 536
Height = 25
ButtonHeight = 21
ButtonWidth = 65
Caption = 'ToolBar1'
ShowCaptions = True
TabOrder = 2
object ToolButton1: TToolButton
Left = 0
Top = 2
Caption = 'ToolButton1'
ImageIndex = 0
end
object ToolButton2: TToolButton
Left = 65
Top = 2
Caption = 'ToolButton2'
ImageIndex = 1
end
object ToolButton3: TToolButton
Left = 130
Top = 2
Width = 8
Caption = 'ToolButton3'
ImageIndex = 2
Style = tbsSeparator
end
object ToolButton4: TToolButton
Left = 138
Top = 2
Caption = 'ToolButton4'
ImageIndex = 2
end
object ToolButton5: TToolButton
Left = 203
Top = 2
Caption = 'ToolButton5'
ImageIndex = 3
end
object ToolButton6: TToolButton
Left = 268
Top = 2
Caption = 'ToolButton6'
ImageIndex = 4
end
end
object Edit1: TEdit
Left = 168
Top = 56
Width = 105
Height = 21
TabOrder = 3
end
object btnAutoSize: TButton
Left = 232
Top = 192
Width = 75
Height = 25
Caption = 'AutoSize False'
TabOrder = 4
OnClick = btnAutoSizeClick
end
end
_____________________________________________________________________
pas File
_____________________________________________________________________
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ToolWin;
type
TForm1 = class(TForm)
btnShowCaption: TButton;
btnChangeSize: TButton;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
Edit1: TEdit;
btnAutoSize: TButton;
procedure FormCreate(Sender: TObject);
procedure btnShowCaptionClick(Sender: TObject);
procedure btnChangeSizeClick(Sender: TObject);
procedure btnAutoSizeClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.Canvas.Brush.Style := bsClear;
end;
procedure TForm1.btnShowCaptionClick(Sender: TObject);
begin
ToolBar1.ShowCaptions := not ToolBar1.ShowCaptions;
end;
procedure TForm1.btnChangeSizeClick(Sender: TObject);
begin
ToolBar1.ButtonWidth := StrToInt(edit1.Text);
end;
procedure TForm1.btnAutoSizeClick(Sender: TObject);
begin
ToolBar1.AutoSize := not ToolBar1.AutoSize;
if ToolBar1.AutoSize then
btnAutoSize.Caption := 'AutoSize True'
else
btnAutoSize.Caption := 'AutoSize False';
end;
end.
____________________________________________________________________
当你按ShowCaption把Caption去掉时再在edit框中输入一个数字按ChangSize键
就可以了。你编译试试。呵呵。