Delphi 之 工具栏组件(TToolBar)


本文整理自网络,侵删。

 
  工具栏组件(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);
var
  bitmap:TBitmap;
begin
  bitmap:= 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);
var
  bitmap:TBitmap;
begin
  bitmap:= 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);
begin
  ToolBar1.ShowCaptions:= True;
  ToolBar1.flat:= true;
end;
end.



示例3 按钮OnClick事件实例


procedure TForm1.ToolButton1Click(Sender: TObject);
begin
  case (Sender as TToolButton).index of
  0: begin
       ShowMessage('打开程序');
     end;
  1: begin
       ShowMessage('保存程序');
     end;
  end;
end;
end.

来源:https://www.cnblogs.com/delphi2014/p/4024922.html

相关阅读 >>

Delphi编程启动服务停止服务新建服务的方法

Delphi里label显示多行文本的两种方法

Delphi-获取毫秒-计算代码运行的时间

Delphi7判断字符是否是数字

Delphi复制文件时,如何显示进度条

Delphi保存网页中的图片

winapi 字符及字符串函数(3): charupper - 字符或字符串转大写

Delphi 使richedit中的链接可以点击

Delphi debug release区别是什么?

processid, process handle, window handle 之间的互相转换

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...