欢迎光临
我们一直在努力

自适应屏幕分辨率的基类窗口(pb)-数据库专栏,其他相关

建站超值云服务器,限时71元/月

做一个自适应屏幕分辨率的窗口,当成一个应用程序中所有窗体的基类。这样整个程序可以很好的适应屏幕分辨率的改变。实现的原理很简单,就是在窗口打开的时候去resize窗口和窗口中的控件大小,位置。参看下面的源代码,可以很容易的看懂。

1。新建一个窗口。

为窗口写一个函数f_resize()大部分工作就在这里。
无输入参数
返回值为整形:

environment env
integer ii_screenwidth,ii_screenheight
double wradio,hradio,radio
integer ii_winbolderwidth,ii_winbolderheight
getenvironment(env)
ii_winbolderwidth=this.width – this.workspacewidth()//取得窗体的边框宽度
ii_winbolderheight=this.height – this.workspaceheight()
ii_screenwidth=env.screenwidth
ii_screenheight=env.screenheight
//compute the radio that need be resize

wradio=ii_screenwidth/800 //标准认为屏幕分辨率为800*600
hradio=ii_screenheight/600//计算出屏幕相对800*600分辨率的变化量
radio=min(wradio,hradio)
if radio=1.0 then //if the screen is default 800*600
 return 0
end if
this.hide()
this.width=(this.width – ii_winbolderwidth)*radio + ii_winbolderwidth
this.height=(this.height – ii_winbolderheight)*radio + ii_winbolderheight
integer i
dragobject temp//用于取各种控件

for i=1 to upperbound(this.control)
 temp=this.control[i]//调整大小,位置
 temp.width=temp.width*radio
 temp.x=temp.x*radio
 temp.y=temp.y*radio
 temp.height=temp.height*radio
 choose case typeof(temp)
  case tab!
   tab mtab
   mtab=temp
   mtab.textsize =  mtab.textsize*radio//设置字体
  case commandbutton!
   commandbutton cb
   cb = temp
   cb.textsize =  cb.textsize*radio

  case singlelineedit!
   singlelineedit sle
   sle = temp
   sle.textsize=sle.textsize*radio
  case editmask!
   editmask em
   em = temp
   em.textsize =  em.textsize*radio
 
  case statictext!
   statictext st
   st = temp
   st.textsize = st.textsize*radio

  case datawindow! // datawindows get zoomed
   datawindow dw
   dw = temp
   dw.object.datawindow.zoom = string(int(radio*100))//注意datawindow与其它控件的不同

  case picturebutton!
   picturebutton pb
   pb = temp
   pb.textsize =  pb.textsize*radio

  case checkbox!
   checkbox cbx
   cbx = temp
   cbx.textsize =  cbx.textsize*radio

  case dropdownlistbox!
   dropdownlistbox ddlb
   ddlb = temp
   ddlb.textsize =  ddlb.textsize*radio

  case groupbox!
   groupbox gb
   gb = temp
   gb.textsize =  gb.textsize*radio

  case listbox!
   listbox lb
   lb = temp
   lb.textsize  =  lb.textsize*radio

  case multilineedit!
   multilineedit mle
   mle = temp
   mle.textsize = mle.textsize*radio

  case radiobutton!
   radiobutton rb
   rb = temp
   rb.textsize =  rb.textsize*radio

 end choose
next
this.show()
return 0

函数写好以后,在窗体的open事件里调用该函数即可.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 自适应屏幕分辨率的基类窗口(pb)-数据库专栏,其他相关
分享到: 更多 (0)