hur.cn - 华软网

 热门搜索

怎样使pb窗口中的控件随窗口的大小而变大变小?

  作者:未知    来源:网络    更新时间:2017/9/29
我用的是pb6.5,vb,vc中可以实现的,我在pb中用数据窗口做了一个状态栏,怎样才能实现其大小随窗口的变化而变化啊?高手指点
------华软网友回答------
留mail,发给你
------华软网友回复------
我给你一个自动调整控件大小的例子,不过该方法只能动态改变PB本身的dragobject控件,对于用户自定义的控件不起作用。代码挺长的,但是涵盖了PB自带的所有控件,代码倒是简单易懂。哈哈,参考一下吧。
我分几不分给你啊!
声明窗口的实例变量:
// 定义数组,记录各控件与窗口的位置、大小比例
real       ir_x[]
real       ir_y[]
real       ir_width[]
real       ir_height[] 

//定义控件
checkbox                     icbx_obj
radiobutton                  irb_obj
commandbutton                icb_obj
datawindow                   idw_obj
dropdownlistbox              iddlb_obj
dropdownpicturelistbox      iddplb_obj
editmask                     iem_obj
groupbox                     igb_obj
HProgressBar   ihpb_obj
hscrollbar                   ihsb_obj
HTrackBar   ihtb_obj
line                         iln_obj
listbox                      ilb_obj
listview                     ilv_obj
multilineedit                imle_obj
Oval   iov_obj
picture                      ip_obj
picturebutton                ipb_obj
PictureHyperLink   iphl_obj
picturelistbox               iplb_obj
singlelineedit               isle_obj
Rectangle   ir_obj
RoundRectangle   irr_obj
tab                          it_obj
treeview                     itv_obj
userobject                   iuo_obj
vscrollbar                   ivsb_obj
graph                        igr_obj
olecontrol                   iole_obj
richtextedit                 irte_obj
statictext                   ist_obj
StaticHyperLink   ishl_obj
VProgressBar   ivpb_obj
VTrackBar   ivtb_obj

------华软网友回复------
在窗口的open事件下编写以下脚本:
Integer li_count
Integer li_i
Long    ll_width
Long    ll_height

ll_width = this.workspacewidth()
ll_height = this.workspaceheight()


// 窗口内控件数
li_count = upperbound(this.control[])


// 循环记录各控件大小与窗口大小的比例
FOR li_i = 1 TO li_count
CHOOSE CASE this.control[li_i].typeof()
CASE checkbox!
icbx_obj = this.control[li_i]
ir_x[li_i] = round(icbx_obj.x / ll_width, 3)
ir_y[li_i] = round(icbx_obj.y / ll_height, 3)
ir_width[li_i] = round(icbx_obj.width / ll_width, 3)
ir_height[li_i] = round(icbx_obj.height / ll_height, 3)

CASE radiobutton!
irb_obj = this.control[li_i]
ir_x[li_i] = round(irb_obj.x / ll_width, 3)
ir_y[li_i] = round(irb_obj.y / ll_height, 3)
ir_width[li_i] = round(irb_obj.width / ll_width, 3)
ir_height[li_i] = round(irb_obj.height / ll_height, 3)

CASE commandbutton!
icb_obj = this.control[li_i]
ir_x[li_i] = round(icb_obj.x / ll_width, 3)
ir_y[li_i] = round(icb_obj.y / ll_height, 3)
ir_width[li_i] = round(icb_obj.width / ll_width, 3)
ir_height[li_i] = round(icb_obj.height / ll_height, 3)

CASE picture!
ip_obj = this.control[li_i]
ir_x[li_i] = round(ip_obj.x / ll_width, 3)
ir_y[li_i] = round(ip_obj.y / ll_height, 3)
ir_width[li_i] = round(ip_obj.width / ll_width, 3)
ir_height[li_i] = round(ip_obj.height / ll_height, 3)

CASE datawindow!
idw_obj = this.control[li_i]
ir_x[li_i] = round(idw_obj.x / ll_width, 3)
ir_y[li_i] = round(idw_obj.y / ll_height, 3)
ir_width[li_i] = round(idw_obj.width / ll_width, 3)
ir_height[li_i] = round(idw_obj.height / ll_height, 3)

CASE dropdownlistbox!
iddlb_obj = this.control[li_i]
ir_x[li_i] = round(iddlb_obj.x / ll_width, 3)
ir_y[li_i] = round(iddlb_obj.y / ll_height, 3)
ir_width[li_i] = round(iddlb_obj.width / ll_width, 3)
ir_height[li_i] = round(iddlb_obj.height / ll_height, 3)

CASE dropdownpicturelistbox!
iddplb_obj = this.control[li_i]
ir_x[li_i] = round(iddplb_obj.x / ll_width, 3)
ir_y[li_i] = round(iddplb_obj.y / ll_height, 3)
ir_width[li_i] = round(iddplb_obj.width / ll_width, 3)
ir_height[li_i] = round(iddplb_obj.height / ll_height, 3)

CASE listbox!
ilb_obj = this.control[li_i]
ir_x[li_i] = round(ilb_obj.x / ll_width, 3)
ir_y[li_i] = round(ilb_obj.y / ll_height, 3)
ir_width[li_i] = round(ilb_obj.width / ll_width, 3)
ir_height[li_i] = round(ilb_obj.height / ll_height, 3)

CASE multilineedit!
imle_obj = this.control[li_i]
ir_x[li_i] = round(imle_obj.x / ll_width, 3)
ir_y[li_i] = round(imle_obj.y / ll_height, 3)
ir_width[li_i] = round(imle_obj.width / ll_width, 3)
ir_height[li_i] = round(imle_obj.height / ll_height, 3)

------华软网友回复------
CASE editmask!
iem_obj = this.control[li_i]
ir_x[li_i] = round(iem_obj.x / ll_width, 3)
ir_y[li_i] = round(iem_obj.y / ll_height, 3)
ir_width[li_i] = round(iem_obj.width / ll_width, 3)
ir_height[li_i] = round(iem_obj.height / ll_height, 3)

CASE tab!
it_obj = this.control[li_i]
ir_x[li_i] = round(it_obj.x / ll_width, 3)
ir_y[li_i] = round(it_obj.y / ll_height, 3)
ir_width[li_i] = round(it_obj.width / ll_width, 3)
ir_height[li_i] = round(it_obj.height / ll_height, 3)

CASE groupbox!
igb_obj = this.control[li_i]
ir_x[li_i] = round(igb_obj.x / ll_width, 3)
ir_y[li_i] = round(igb_obj.y / ll_height, 3)
ir_width[li_i] = round(igb_obj.width / ll_width, 3)
ir_height[li_i] = round(igb_obj.height / ll_height, 3)

CASE hscrollbar!
ihsb_obj = this.control[li_i]
ir_x[li_i] = round(ihsb_obj.x / ll_width, 3)
ir_y[li_i] = round(ihsb_obj.y / ll_height, 3)
ir_width[li_i] = round(ihsb_obj.width / ll_width, 3)
ir_height[li_i] = round(ihsb_obj.height / ll_height, 3)

CASE listview!
ilv_obj = this.control[li_i]
ir_x[li_i] = round(ilv_obj.x / ll_width, 3)
ir_y[li_i] = round(ilv_obj.y / ll_height, 3)
ir_width[li_i] = round(ilv_obj.width / ll_width, 3)
ir_height[li_i] = round(ilv_obj.height / ll_height, 3)

CASE picturebutton!
ipb_obj = this.control[li_i]
ir_x[li_i] = round(ipb_obj.x / ll_width, 3)
ir_y[li_i] = round(ipb_obj.y / ll_height, 3)
ir_width[li_i] = round(ipb_obj.width / ll_width, 3)
ir_height[li_i] = round(ipb_obj.height / ll_height, 3)

CASE picturelistbox!
iplb_obj = this.control[li_i]
ir_x[li_i] = round(iplb_obj.x / ll_width, 3)
ir_y[li_i] = round(iplb_obj.y / ll_height, 3)
ir_width[li_i] = round(iplb_obj.width / ll_width, 3)
ir_height[li_i] = round(iplb_obj.height / ll_height, 3)

CASE singlelineedit!
isle_obj = this.control[li_i]
ir_x[li_i] = round(isle_obj.x / ll_width, 3)
ir_y[li_i] = round(isle_obj.y / ll_height, 3)
ir_width[li_i] = round(isle_obj.width / ll_width, 3)
ir_height[li_i] = round(isle_obj.height / ll_height, 3)

CASE treeview!
itv_obj = this.control[li_i]
ir_x[li_i] = round(itv_obj.x / ll_width, 3)
ir_y[li_i] = round(itv_obj.y / ll_height, 3)
ir_width[li_i] = round(itv_obj.width / ll_width, 3)
ir_height[li_i] = round(itv_obj.height / ll_height, 3)
CASE userobject!
iuo_obj = this.control[li_i]
ir_x[li_i] = round(iuo_obj.x / ll_width, 3)
ir_y[li_i] = round(iuo_obj.y / ll_height, 3)
ir_width[li_i] = round(iuo_obj.width / ll_width, 3)
ir_height[li_i] = round(iuo_obj.height / ll_height, 3)

CASE vscrollbar!
ivsb_obj = this.control[li_i]
ir_x[li_i] = round(ivsb_obj.x / ll_width, 3)
ir_y[li_i] = round(ivsb_obj.y / ll_height, 3)
ir_width[li_i] = round(ivsb_obj.width / ll_width, 3)
ir_height[li_i] = round(ivsb_obj.height / ll_height, 3)

CASE graph!
igr_obj = this.control[li_i]
ir_x[li_i] = round(igr_obj.x / ll_width, 3)
ir_y[li_i] = round(igr_obj.y / ll_height, 3)
ir_width[li_i] = round(igr_obj.width / ll_width, 3)
ir_height[li_i] = round(igr_obj.height / ll_height, 3)

CASE olecontrol!
iole_obj = this.control[li_i]
ir_x[li_i] = round(iole_obj.x / ll_width, 3)
ir_y[li_i] = round(iole_obj.y / ll_height, 3)
ir_width[li_i] = round(iole_obj.width / ll_width, 3)
ir_height[li_i] = round(iole_obj.height / ll_height, 3)

CASE richtextedit!
irte_obj = this.control[li_i]
ir_x[li_i] = round(irte_obj.x / ll_width, 3)
ir_y[li_i] = round(irte_obj.y / ll_height, 3)
ir_width[li_i] = round(irte_obj.width / ll_width, 3)
ir_height[li_i] = round(irte_obj.height / ll_height, 3)

CASE statictext!
ist_obj = this.control[li_i]
ir_x[li_i] = round(ist_obj.x / ll_width, 3)
ir_y[li_i] = round(ist_obj.y / ll_height, 3)
ir_width[li_i] = round(ist_obj.width / ll_width, 3)
ir_height[li_i] = round(ist_obj.height / ll_height, 3)

CASE line!
iln_obj = this.control[li_i]
ir_x[li_i] = round(iln_obj.beginx / ll_width, 3)
ir_y[li_i] = round(iln_obj.beginy / ll_height, 3)
ir_width[li_i] = round(iln_obj.endx / ll_width, 3)
ir_height[li_i] = round(iln_obj.endy / ll_height, 3)

case HProgressBar!
ihpb_obj = This.control[li_i]
ir_x[li_i] = round(ihpb_obj.x / ll_width, 3)
ir_y[li_i] = round(ihpb_obj.y / ll_height, 3)
ir_width[li_i] = round(ihpb_obj.width / ll_width, 3)
ir_height[li_i] = round(ihpb_obj.height / ll_height, 3)

case HTrackBar!
ihtb_obj = This.control[li_i]
ir_x[li_i] = round(ihtb_obj.x / ll_width, 3)
ir_y[li_i] = round(ihtb_obj.y / ll_height, 3)
ir_width[li_i] = round(ihtb_obj.width / ll_width, 3)
ir_height[li_i] = round(ihtb_obj.height / ll_height, 3)
  
case Oval!
iov_obj = This.control[li_i]
ir_x[li_i] = round(iov_obj.x / ll_width, 3)
ir_y[li_i] = round(iov_obj.y / ll_height, 3)
ir_width[li_i] = round(iov_obj.width / ll_width, 3)
ir_height[li_i] = round(iov_obj.height / ll_height, 3)
  
case PictureHyperLink!
iphl_obj = This.control[li_i]
ir_x[li_i] = round(iphl_obj.x / ll_width, 3)
ir_y[li_i] = round(iphl_obj.y / ll_height, 3)
ir_width[li_i] = round(iphl_obj.width / ll_width, 3)
ir_height[li_i] = round(iphl_obj.height / ll_height, 3)
  
case Rectangle!
ir_obj = This.control[li_i]
ir_x[li_i] = round(ir_obj.x / ll_width, 3)
ir_y[li_i] = round(ir_obj.y / ll_height, 3)
ir_width[li_i] = round(ir_obj.width / ll_width, 3)
ir_height[li_i] = round(ir_obj.height / ll_height, 3)
  
case RoundRectangle!
irr_obj = This.control[li_i]
ir_x[li_i] = round(irr_obj.x / ll_width, 3)
ir_y[li_i] = round(irr_obj.y / ll_height, 3)
ir_width[li_i] = round(irr_obj.width / ll_width, 3)
ir_height[li_i] = round(irr_obj.height / ll_height, 3)

case vscrollbar!
ivsb_obj = This.control[li_i]
ir_x[li_i] = round(ivsb_obj.x / ll_width, 3)
ir_y[li_i] = round(ivsb_obj.y / ll_height, 3)
ir_width[li_i] = round(ivsb_obj.width / ll_width, 3)
ir_height[li_i] = round(ivsb_obj.height / ll_height, 3)

case StaticHyperLink!
ishl_obj = This.control[li_i]
ir_x[li_i] = round(ishl_obj.x / ll_width, 3)
ir_y[li_i] = round(ishl_obj.y / ll_height, 3)
ir_width[li_i] = round(ishl_obj.width / ll_width, 3)
ir_height[li_i] = round(ishl_obj.height / ll_height, 3)

case VProgressBar!
ivpb_obj = This.control[li_i]
ir_x[li_i] = round(ivpb_obj.x / ll_width, 3)
ir_y[li_i] = round(ivpb_obj.y / ll_height, 3)
ir_width[li_i] = round(ivpb_obj.width / ll_width, 3)
ir_height[li_i] = round(ivpb_obj.height / ll_height, 3)

case VTrackBar!
ivtb_obj = This.control[li_i]
ir_x[li_i] = round(ivtb_obj.x / ll_width, 3)
ir_y[li_i] = round(ivtb_obj.y / ll_height, 3)
ir_width[li_i] = round(ivtb_obj.width / ll_width, 3)
ir_height[li_i] = round(ivtb_obj.height / ll_height, 3)
End Choose
Next

------华软网友回复------
我的email是cquptlilian@yeah.net
------华软网友回复------
数据窗口所在窗口的Resize事件下写上一句话:Resize(dw_datamon,this.Workspacewidth()-50,this.Workspaceheight()-50)其中dw_datamon是数据窗口的名字,数字50可以调整。

不知道可行否
------华软网友回复------
控件自动调整大小的例子已经给你发到你的邮箱里了,查一下吧。      
华软声明:本内容来自网络,如有侵犯您版权请来信指出,本站立即删除。