![]() |
|
||||||||||||||
| | 网站首页 | 数据库教程 | web编程 | 服务器 | 程序设计 | | ||
|
||
|
|||||||||||||||||||||||||||||||||
| 利用PB数据窗口特征制作进度条 | |||||||||||||||||||||||||||||||||
作者:佚名 文章来源:不详 点击数: 更新时间:2007-8-16 ![]() |
|||||||||||||||||||||||||||||||||
|
PowerBuilder的6.5以前版本没有提供进度条,因此大多数程序员总是自己在程序中利用两个statictext控件进行编程产生进度效果。但是由于包括statictext控件在内的所有窗口内使用的控件没有透明色即transparent,进度条的文字显示无法与进度条进行重叠,只得在进度条外的其它位置放置一statictext控件用以显示进度情况,这样即浪费了空间,又不美观。
但我们知道,数据窗口内的静态文本的字体属性是有transparent(透明)的,笔者通过研究PowerBuilder的数据窗口控件特征,摸索出一利用数据窗口等制作进度条的方法,充分解决了以上难题,还能任意改变宽度及背景、伸缩块及文字的颜色,并封装成了用户对象以方便调用。下面就介绍这一方法。 1、首先建立一数据源为Enternal(外部)、风格为Freefrom的数据窗口d_schedule_bar,输入一个字段。确定后在数据窗口画板中删除该字段,再增加两个statictext控件,这样数据窗口加上字段标识的那个一共三个statictext控件,分别命名为:st_back、st_move、st_text,调整使其宽、高度相等,设st_back的background.color为ButtonFace,st_move的background.color为Teal,st_text的background.color为transparent,st_text的color为black。表述如下:
保存之前选择st_move,从Edit菜单中选择Bring to Front,再选择st_text重复上述操作,使三个 statictext控件的位置层从外向里按st_text、st_move、st_back排序,以防被显示屏蔽(这一点非常重要!)。 2、新建一可视定制用户对象uo_ schedule_bar,以其中放置一数据窗口dw_1,数? 为d_schedule_bar。定义两个int实例变量 ii_percent、ii_width。 下面就开始骗程吧! (1)编写函数uf_setwidth(integer ai_width) 参数及类型:integer ai_width 作用:改变进度条宽度: 返回值:无 函数体: IF ai_width $#@62; 0 THEN ii_width = ai_width dw_1.resize (ai_width + 15,dw_1.height) dw_1.modify ( "st_back.width=" + string(ai_width) ) dw_1.modify ( "st_text.width=" + string(ai_width) ) this.resize ( ai_width + 50, this.height ) END IF (2)编写函数uf_schedule_move(integer ai_schedule) 参数及类型:integer ai_schedule 作用:显示进度 返回值:无 函数体: int li_AllWidth,li_schedule IF ai_schedule $#@62; 100 THEN ai_schedule = 100 ii_percent = 100 END IF IF ai_schedule $#@60; 0 THEN ai_schedule = 0 END IF ii_percent = ai_schedule li_AllWidth = integer(dw_1.describe ( "st_back.width" )) IF ai_schedule $#@62;= 0 THEN li_schedule = li_AllWidth * (ai_schedule / 100) END IF dw_1.modify ( "st_move.width=" + string(li_schedule) ) dw_1.modify ( "st_text.text=" + string (ai_schedule) + "%" ) (3)编写三个颜色控制函数以改变背景、伸缩条、文字的颜色。 函数名:uf_change_back_color 参数:double a_color 函数体: dw_1.modify ( "st_back.background.color = "+string(a_color)) 函数名:uf_change_move_bar_color 参数:double a_color 函数体: dw_1.modify ( "st_move.background.color = "+string(a_color)) 函数名:uf_change_text_color 参数:double a_color 函数体: dw_1.modify ( "st_text.color = "+string(a_color)) (4)在constructor事件中输入以下代码: dw_1.insertrow (0) this.uf_schedule_move ( 0 ) ii_width = this.width 好了,一个标准的进度条用户对象就封象好了!在程序中任意地使用吧!
|
|||||||||||||||||||||||||||||||||
| 文章录入:admin 责任编辑:admin | |||||||||||||||||||||||||||||||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||||||||||||||||||||||||||||||
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 网站地图 | 管理登录 | | |||
|