Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)aaapublished in(发表于) 2014/7/19 0:13:56 delphi高级vcl组件状态栏组件(TStatusBar)使用实例
delphi高级vcl组件状态栏组件(TStatusBar)使用实例
状态栏组件(TStatusBar)TStatusBar 组件是用来显示当前程序状态的。状态栏可以分为多个面板,用来显示不同状态的内容。1.TStatusBar 组件的典型用法在窗体中添加了TStatusBar 组件后,Align 属性默认设置为alBottom,所以TStatusBar 组件默认停靠在窗体的最下边,并且宽度会自动适应窗体宽度的改变。在一个TStatusBar 组件中可以有多个面板。选中TStatusBar 组件后,单击鼠标右键,可以通过菜单命令“Panels Edit...”打开状态栏编辑器,可以添加、修改状态栏中的面板,还可以设置状态栏中各个面板的显示内容及面板的宽度等。当然,在程序运行期间,也可以通过代码动态改变各个面板中的内容。用TStatusBar 组件制作的状态栏可以分成几个窗格,每个窗格分别显示不同的信息。例如,一个字处理程序的状态栏可以分别显示当前页码、是否存盘、改写还是插入语言等信息。对于用TStatusBar 组件制作的状态栏来说,状态栏上的每一个窗格都是一个TStatusPanel 对象,这些窗格是由TStatusPanels 对象(Panels 属性)管理的。在设计期,可以在Object Inspector 中单击Panels 属性旁边的省略号“?”按钮来打开窗格编辑器;也可以用光标右键单击TStatusBar 组件,在弹出的菜单中选择?Panels Editor?命令来打开窗格编辑器。然后,建立和编辑窗格(TStatusPanel 对象)的属性。单击工具栏上的?Add new?按钮可以新增加一个窗格;单击?Delete selected?按钮可以删除一个窗格;单击上下箭头可以把节前移和后移。 通过Object Inspector 可以设置每一个窗格的属性。其中,Alignment 属性用于设置文字在窗格上的排列方式,设为taLeftJustify 表示左对齐,设为taCenter 表示居中,设为taRightJustify 表示右对齐;Bevel 属性用于设置窗格是凹还是凸;Style 属性用于设置窗格的风格,设为psText 表示窗格上只能显示文字,设为psOwnerDraw 表示可以在窗格上画出图形;Text 属性用于指定要在窗格上显示的文字;Width 属性用于设置窗格的宽度。 在运行期,通过TStatusPanels 对象可以访问状态栏的每一个窗格(TStatusPanel 对象)。程序示例代码如下: procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if ssLeft in Shift then {make sure button is down} begin if Y>StartY then begin StatusBar1.Panels[0].Text:=’Top:’+IntToStr(StartY); StatusBar1.Panels[2].Text:=’Bottom:’+IntToStr(Y); end else begin StatusBar1.Panels[0].Text:=’Top:’+IntToStr(Y); StatusBar1.Panels[2].Text:=’Bottom:’+IntToStr(StartY); end; if X>StartX then begin StatusBar1.Panels[1].Text:=’Left:’+IntToStr(StartX); StatusBar1.Panels[3].Text:=’Right:’+IntToStr(X); end else begin StatusBar1.Panels[1].Text:=’Left:’+IntToStr(X); StatusBar1.Panels[3].Text:=’Right:’+IntToStr(StartX); end; end; end;
赞