工具栏组件(TToolBar)为用户提供了快捷菜单的访问方式。
Buttions
列出工具栏中的工具按钮,其中保存了TToolButton实例的列表
Canvas
在OnCustomDraw或OnCustomDrawItem事件中使用该属性可以在工具栏上画图。
Constraints
规定TToolBar的大小限制
Customizable
设置该属性为True,允许用户在程序运行时添加、删除和移动工具栏按钮。用户可以按Shift键拖动按钮到一个新的位置,或者拖动它离开
CusstiomizeKeyName
使用该属性指定当前用户首次显示工具栏定制的对话框时,保存其按钮配置的位置
CusstiomizeValueName
使用该属性指定当前用户首次显示工具栏定制的对话框时,保存其按钮配置名称的位置
Disabledimages
该属性包含一个图像列表,每个工具按钮的ImageIndex属性确定了在该按钮上要显示的图标。
Image
为TToolBar提供一个图像列表
Menu
使用该属性可使工具栏上的按钮与菜单中的项相对应
示例 利用Canvas属性在TToolBar组件上绘图
procedure TForm1.ToolBar1CustomDraw(Sender: TToolBar; const ARect: TRect;var DefaultDraw: Boolean);varbitmap:TBitmap;beginbitmap:= TBitmap.Create;bitmap.LoadFromFile('C:\Documents and Settings\All Users\Documents\My Pictures\示例图片\MM1.bmp');ToolBar1.Canvas.StretchDraw(ARect,bitmap);bitmap.Free;end;
示例2 :制作透明按钮效果
procedure TForm1.ToolBar1CustomDraw(Sender: TToolBar; const ARect: TRect;var DefaultDraw: Boolean);varbitmap:TBitmap;beginbitmap:= TBitmap.Create;bitmap.LoadFromFile('C:\Documents and Settings\All Users\Documents\My Pictures\示例图片\MM1.bmp');ToolBar1.Canvas.StretchDraw(ARect,bitmap);bitmap.Free;end;procedure TForm1.FormCreate(Sender: TObject);beginToolBar1.ShowCaptions:= True;ToolBar1.flat:= true;end;end.
示例3 按钮OnClick事件实例
procedure TForm1.ToolButton1Click(Sender: TObject);begincase (Sender as TToolButton).index of0: beginShowMessage('打开程序');end;1: beginShowMessage('保存程序');end;end;end;end.