自適應屏幕分辨率的基類窗口(pb)
2024-07-21 02:10:25
供稿:網友
做一個自適應屏幕分辨率的窗口,當成一個應用程序中所有窗體的基類。這樣整個程序可以很好的適應屏幕分辨率的改變。實現(xiàn)的原理很簡單,就是在窗口打開的時候去resize窗口和窗口中的控件大小,位置。參看下面的源代碼,可以很容易的看懂。
1。新建一個窗口。
為窗口寫一個函數(shù)f_resize()大部分工作就在這里。
無輸入參數(shù)
返回值為整形:
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
函數(shù)寫好以后,在窗體的open事件里調用該函數(shù)即可.